简体   繁体   中英

VB.net databinding linq

can someone explain why databinding to textbox2 works but not for textbox1?

Using a BindingSource as Datasource, but using the query directly does also not work.

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

every time i move out from textbox1 the initial value is displayed againe. _tia rene

edit: got this working. when using nullable values you have to pass in some more parameters ...

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

did the trick

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM