I need to allow nulls when I programmatically bind a textbox
I was thinking I should just change the value to "" when a null value has been read from the datasoure. But then I thought maybe there is a property that allows this. is there?
开发者_如何学PythontxtComments.DataBindings.Add("Text", rowEquipItem, "Comment")
You can use the Binding.Format
event (MSDN):
Private Sub AddBinding
Dim b As Binding = New Binding("Text", rowEquipItem, "Comment")
AddHandler b.Format, AddressOf nullToEmpty
txtComments.DataBindings.Add(b)
End Sub
Private Sub nullToEmpty(sender As Object, e As ConvertEventArgs)
If e.DesiredType IsNot GetType(String) Then
Exit Sub
End If
If IsDBNull(e.Value) Then
e.Value = ""
End If
End Sub
精彩评论