VB.net数据绑定linq

时间:2012-10-19 09:42:10

标签: .net linq data-binding

有人可以解释为什么数据绑定到textbox2有效,但不能用于textbox1吗?

使用BindingSource作为数据源,但直接使用查询也不起作用。

Private Class DTO1
        Public Property id As Integer        
        Public Property value As Nullable(Of Integer)
        Public Property value2 As String
    End Class

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Dim lst As New List(Of DTO1)
        Dim a As New DTO1
        a.id = 1
        Dim o As Object = 1
        a.value = o
        lst.Add(a)

        a = New DTO1
        a.id = 2
        a.value = Nothing
        lst.Add(a)

        bs.DataSource = (From p In lst Select p).ToList
        grd.DataSource = bs
        TextBox1.DataBindings.Add("text", grd.DataSource, "value")
        TextBox2.DataBindings.Add("text", grd.DataSource, "value2")
    End Sub

每次从textbox1移出时,初始值都显示为againe。 _tia 雷

编辑:让这个工作。当使用可空值时,您必须传递更多参数......

Me.DataBindings.Add(pr_PropertyName, pr_Datasource, pr_Datamember, True, DataSourceUpdateMode.OnValidation, Nothing)

做了这个伎俩

1 个答案:

答案 0 :(得分:0)

只是回答了这个问题......

.DataBindings.Add(pr_PropertyName, pr_Datasource, pr_Datamember, True, DataSourceUpdateMode.OnValidation, Nothing)