Results 1 to 2 of 2

Thread: Custom Datetime Picker

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Oklahoma, USA

    Custom Datetime Picker

    I have a form with several DateTime fields many will remain blank and are nullable fields on the database. Of course the problem is the datetime picker will not allow null values. My solution is to make the field a textbox and format the data in the advanced option of the binding. This works but now I would like to add a button that will popup a datetime picker and allow the user to select the date from a calendar. I know I have seen such a thing in the past but can't seem to find the code now. Can anyone help.

    Name:  Untitled.jpg
Views: 275
Size:  49.3 KB

  2. #2
    Join Date
    Sep 2006

    Re: Custom Datetime Picker

    It is possible to show an empty DateTimePicker like this

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If IsDate(dt) Then ' dt is a date string from the database
                DateTimePicker1.Format = DateTimePickerFormat.Long
                DateTimePicker1.Value = dt
                DateTimePicker1.CustomFormat = " "  'An empty SPACE
                DateTimePicker1.Format = DateTimePickerFormat.Custom
            End If
        End Sub
        Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
            If DateTimePicker1.Format = DateTimePickerFormat.Custom Then ' restore default format
                DateTimePicker1.Format = DateTimePickerFormat.Long
            End If
        End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width