I've got a property on a custom business object bound to a textbox.
In my binding, I've set the nullValue = String.Empty
When I type in the textbox, then erase the text in my textbox and try to leave... it tries to set the string property in my business object to "Nothing"
This is a problem for me because I've got code that checks the length of the string for validation purposes. I know I could handle it at the business object level but I am completely perplexed by the fact that it's trying to set the string to "Nothing"
PS. I've got a Parse Event on the binding, and at that point when I check e.Value it evaluates to "" (String.Empty) but as soon as it leaves that event and tries to set the property the value is Nothing instead of String.Empty
Binding Code:
Parse Event:
(e.Value evaluates to "" so it doesn't even hit the line that sets it to "")
Set For my property (it errors on the value.Length part)
I know I could alter this code to handle nothing but I'd rather not patch the business object to handle the strange databinding problem
In my binding, I've set the nullValue = String.Empty
When I type in the textbox, then erase the text in my textbox and try to leave... it tries to set the string property in my business object to "Nothing"
This is a problem for me because I've got code that checks the length of the string for validation purposes. I know I could handle it at the business object level but I am completely perplexed by the fact that it's trying to set the string to "Nothing"
PS. I've got a Parse Event on the binding, and at that point when I check e.Value it evaluates to "" (String.Empty) but as soon as it leaves that event and tries to set the property the value is Nothing instead of String.Empty
Binding Code:
VB.NET:
Dim binding As New Binding("Text", MyObject, "MyStringProperty", True, DataSourceUpdateMode.OnValidation, String.Empty, Nothing)
AddHandler binding.Parse, AddressOf oBinding_Parse
binding.ControlUpdateMode = ControlUpdateMode.OnPropertyChanged
Control.DataBindings.Add(binding)
Parse Event:
(e.Value evaluates to "" so it doesn't even hit the line that sets it to "")
VB.NET:
Private Sub oBinding_Parse(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs)
If e.DesiredType Is GetType(String) Then
If e.Value Is Nothing Then
e.Value = ""
End If
End If
End Sub
Set For my property (it errors on the value.Length part)
I know I could alter this code to handle nothing but I'd rather not patch the business object to handle the strange databinding problem
VB.NET:
Set(ByVal value As String)
If value.Length > 10 Then
Throw New Exception("Invalid Length")
End If
mMyStringProperty = value
End Set