I've read various workarounds on this, but cannot get any working well. I have a large number of Datetimepickers on a form, all bound to datatables via a BindingSource. Problem being, a lot of the data holds null values for dates, but these display as datetime.now. I want some indication that these are null, not an actual date.
As it happens, I have a 'themer' that iterates through all controls on the form. I add a handler to each on ValueChanged:
ElseIf TypeOf ct Is DateTimePicker Then
Dim dtp = DirectCast(ct, DateTimePicker)
With dtp
AddHandler dtp.ValueChanged, AddressOf Zzapper.Dtp_ValueChanged
End With
Handler:
Public Sub Dtp_ValueChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim dtp As DateTimePicker = DirectCast(sender, DateTimePicker)
Dim result As DateTime
If DateTime.TryParse(dtp.Value, result) Then
dtp.Format = DateTimePickerFormat.Long
Else
dtp.CustomFormat = " "
dtp.Format = DateTimePickerFormat.Custom
End If
However, this does not get fired on null values (discerned via breakpoints and counting how often it gets called - only gets called for non-null values), I'm guessing because technically the value doesn't change in the control itself.
Can anyone else think of a solution?