开发者

I need to allow nulls when I programmatically bind a textbox

开发者 https://www.devze.com 2023-03-23 06:10 出处:网络
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?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消