开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜