Showing posts with label DateTimePicker. Show all posts
Showing posts with label DateTimePicker. Show all posts

Friday, March 27, 2009

Setting the DateTimePicker to a Blank Value

I wanted to use the DateTimePicker control on a data entry form; however, it always has to be set to a value. I did not want to set the date value to Now or some other preset value because it is not clear to the user that the value needs to be set. I found several solutions to this problem, but the one below appears to work and is easy to use.

Initialize the DateTimePicker control to a blank value by setting the Format property to Custom and the CustomFormat property to a space (" "):

DateTimePickerConstDate.CustomFormat = " "
DateTimePickerConstDate.Format = DateTimePickerFormat.Custom


Then, when the value changes, change the Format property back to its original value (or define a usable Custom Format:

Private Sub DateTimePickerConstDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePickerConstDate.ValueChanged

DateTimePickerConstDate.Format = DateTimePickerFormat.Short

End Sub


For more information on this solution and other approaches, see the following:

http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/46b2a370-72ec-485c-9361-bfa505bb6863/