I am trying to format a SQL date in a form. When the date is first created it is <null>. If it is updated, I am able to format it fine. But am fighting what happens when the date is cleared out ie. txtDate.text = ""... to try to work around some of the problems I tried using .minvalue, but seem to be on the wrong track.
I am using Data binding as follows:
Dim dbnPlaceOpened As New Binding("Text", ds, "Placements.DatePlacementStart"
AddHandler dbnPlaceOpened.Format, AddressOf DateToString
AddHandler dbnPlaceOpened.Parse, AddressOf StringToDate
txtPlaceOpened.DataBindings.Add(dbnPlaceOpened)
Protected Sub DateToString(ByVal sender As Object, ByVal e As ConvertEventArgs)
If Not IsDBNull(e.Value) Then
If CType(e.Value, DateTime) = Date.MinValue Then
e.Value = String.Empty
Else
e.Value = CType(e.Value, DateTime).ToShortDateString
End If
Else
e.Value = String.Empty
End If
End Sub
I have tried different styles in the "format" method but am getting an Invalid Cast from "" to Date. Without getting too convoluted, any suggestions??
Thanks,
Bob Taylor
I am using Data binding as follows:
Dim dbnPlaceOpened As New Binding("Text", ds, "Placements.DatePlacementStart"
AddHandler dbnPlaceOpened.Format, AddressOf DateToString
AddHandler dbnPlaceOpened.Parse, AddressOf StringToDate
txtPlaceOpened.DataBindings.Add(dbnPlaceOpened)
Protected Sub DateToString(ByVal sender As Object, ByVal e As ConvertEventArgs)
If Not IsDBNull(e.Value) Then
If CType(e.Value, DateTime) = Date.MinValue Then
e.Value = String.Empty
Else
e.Value = CType(e.Value, DateTime).ToShortDateString
End If
Else
e.Value = String.Empty
End If
End Sub
I have tried different styles in the "format" method but am getting an Invalid Cast from "" to Date. Without getting too convoluted, any suggestions??
Thanks,
Bob Taylor