有人可以解释为什么对 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 移出时,都会再次显示初始值。_tia rene
编辑:得到这个工作。使用可为空值时,您必须传入更多参数...
Me.DataBindings.Add(pr_PropertyName, pr_Datasource, pr_Datamember, True, DataSourceUpdateMode.OnValidation, Nothing)
成功了