R
Rick
I have a business object (class) with some nullable properties declared like
this:
Private _MyProp as Nullable(of Int16)
public Property MyProp as Nullable(Of Int16)
get
Return _MyProp
end get
set(ByVal Value as Nullable(Of Int16))
If not _MyProp.Equals(value) then
_MyProp = Value
NotifyPropertyChanged("MyProp") ' marks the property changed
end if
end set
I can read from my database with no problem for both MyProp's with or
without a value. When MyProp = 1 and I try to set it to Null in a Windows
TextBox, the form will not even let me move to another control. If I change
rows in a datagridview, the value is set back to 0.
So, I added an OnValidate event like this:
if String.IsNullOrEmpty(myControl.Text) then _
myBusinessObject.MyProperty = Nothing
Now I can set the nullable property to "Nothing" and it works as expected.
My question is - Is this the normal procedure to set a nullable value or am
I missing some shortcut where I don't have to add the OnValidate event?
Rick
this:
Private _MyProp as Nullable(of Int16)
public Property MyProp as Nullable(Of Int16)
get
Return _MyProp
end get
set(ByVal Value as Nullable(Of Int16))
If not _MyProp.Equals(value) then
_MyProp = Value
NotifyPropertyChanged("MyProp") ' marks the property changed
end if
end set
I can read from my database with no problem for both MyProp's with or
without a value. When MyProp = 1 and I try to set it to Null in a Windows
TextBox, the form will not even let me move to another control. If I change
rows in a datagridview, the value is set back to 0.
So, I added an OnValidate event like this:
if String.IsNullOrEmpty(myControl.Text) then _
myBusinessObject.MyProperty = Nothing
Now I can set the nullable property to "Nothing" and it works as expected.
My question is - Is this the normal procedure to set a nullable value or am
I missing some shortcut where I don't have to add the OnValidate event?
Rick