none
Check last Datetimepicker before the next date RRS feed

  • Question

  • Hello,

    I have 5 Datetimepickers , how do i make it they have to fill in the previous datetimepicker before the next one ?

    In Formload i make the value " " for the Datetimepickers 

    The Datetimepickers are in the same order as below in the form

    In Formload 
    
    With Datebegin
                .Format = DateTimePickerFormat.Custom
                .CustomFormat = " "
     End With
    
     With Datearrival
                .Format = DateTimePickerFormat.Custom
                .CustomFormat = " "
     End With
    
     With Datestop
                .Format = DateTimePickerFormat.Custom
                .CustomFormat = " "
     End With
    
    With Datedoc
                .Format = DateTimePickerFormat.Custom
                .CustomFormat = " "
     End With
    
    With Dateleave
                .Format = DateTimePickerFormat.Custom
                .CustomFormat = " "
     End With

    I think there is a better way then this

     If Datumarrival.CustomFormat = " " Then
                MsgBox("Fill in last date")
                Datumarrival.CustomFormat = " "
            End If

    When using this i can skip this and go to the next 

    So the Question , how to make the previous date is filled in and not skip this and go to the next one ?

    Friday, February 22, 2019 8:40 PM

Answers

  • Hi

    Here is an example using the Visible property

    ' Form1 with 5 DateTimePickers (1 - 5)
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With DateTimePicker1
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker2
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker3
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker4
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker5
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
      End Sub
    
      Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged, DateTimePicker2.ValueChanged, DateTimePicker3.ValueChanged, DateTimePicker4.ValueChanged, DateTimePicker5.ValueChanged
    
        Dim dtp As DateTimePicker = DirectCast(sender, DateTimePicker)
        Select Case dtp.Name
          Case "DateTimePicker1"
            DateTimePicker2.Visible = True
          Case "DateTimePicker2"
            DateTimePicker3.Visible = True
          Case "DateTimePicker3"
            DateTimePicker4.Visible = True
          Case "DateTimePicker4"
            DateTimePicker5.Visible = True
        End Select
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by KeesBlunder Saturday, February 23, 2019 9:48 AM
    Friday, February 22, 2019 9:47 PM

All replies

  • Hi

    I would use the .Enabled property in such a situation, or possibly, the .Visible property - depending on how I felt at the time.

    Only .Enabling (or making .Visable) when previous one done.

    *

    Also, that is not correct usage for the format/custom format/value of DateTimePickers


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, February 22, 2019 9:39 PM
    Friday, February 22, 2019 9:33 PM
  • Hi

    Here is an example using the Visible property

    ' Form1 with 5 DateTimePickers (1 - 5)
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With DateTimePicker1
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker2
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker3
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker4
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
        With DateTimePicker5
          .Visible = False
          .Value = Now
          .Format = DateTimePickerFormat.Custom
          .CustomFormat = "ddd, dd MMM"
        End With
      End Sub
    
      Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged, DateTimePicker2.ValueChanged, DateTimePicker3.ValueChanged, DateTimePicker4.ValueChanged, DateTimePicker5.ValueChanged
    
        Dim dtp As DateTimePicker = DirectCast(sender, DateTimePicker)
        Select Case dtp.Name
          Case "DateTimePicker1"
            DateTimePicker2.Visible = True
          Case "DateTimePicker2"
            DateTimePicker3.Visible = True
          Case "DateTimePicker3"
            DateTimePicker4.Visible = True
          Case "DateTimePicker4"
            DateTimePicker5.Visible = True
        End Select
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by KeesBlunder Saturday, February 23, 2019 9:48 AM
    Friday, February 22, 2019 9:47 PM
  • Thanks Les,

    I can do something with the code you gave me.

    This line was new to me , did not see this before.

    Useful

    Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged, DateTimePicker2.ValueChanged, DateTimePicker3.ValueChanged, DateTimePicker4.ValueChanged, DateTimePicker5.ValueChanged
    


    Saturday, February 23, 2019 9:48 AM