J
Jack Jackson
In VS2005 VB, is it possible to bind a Nullable property to a data
source (e.g. DataTable) property that is not Nullable? My goal is to
be able to convert DBNull to and from Nothing for Value data types.
I created a derived Binding object with Format and Parse handlers. In
the Format event I am unable to set the event arg's Value property to
a Nullable type. For example, stripping out the code that is not
germane to this discussion:
Protected Overrides Sub OnFormat(ByVal cevent As
System.Windows.Forms.ConvertEventArgs)
dim dt As Nullable(Of DateTime)
dt = Convert.ToDateTime(cevent.Value)
cevent.Value = dt
cevent.Value is defined as Object. The last line sets cevent.Value to
a DateTime, not to a Nullable(Of DateTime). In playing around with
this, I have been unable to get a property defined as Object set to a
Nullable - it always sets it to the value property of the Nullable
object.
Because cevent.Value is a DateTime I get an invalid cast error when
..NET tries to set the Nullable property to cevent.Value.
Is there any way to do the binding?
source (e.g. DataTable) property that is not Nullable? My goal is to
be able to convert DBNull to and from Nothing for Value data types.
I created a derived Binding object with Format and Parse handlers. In
the Format event I am unable to set the event arg's Value property to
a Nullable type. For example, stripping out the code that is not
germane to this discussion:
Protected Overrides Sub OnFormat(ByVal cevent As
System.Windows.Forms.ConvertEventArgs)
dim dt As Nullable(Of DateTime)
dt = Convert.ToDateTime(cevent.Value)
cevent.Value = dt
cevent.Value is defined as Object. The last line sets cevent.Value to
a DateTime, not to a Nullable(Of DateTime). In playing around with
this, I have been unable to get a property defined as Object set to a
Nullable - it always sets it to the value property of the Nullable
object.
Because cevent.Value is a DateTime I get an invalid cast error when
..NET tries to set the Nullable property to cevent.Value.
Is there any way to do the binding?