[英]VB.net databinding linq
can someone explain why databinding to textbox2 works but not for textbox1? 有人可以解释为什么对textbox2进行数据绑定而不对textbox1有效吗?
Using a BindingSource as Datasource, but using the query directly does also not work. 将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
every time i move out from textbox1 the initial value is displayed againe. 每次我从textbox1移出时,都会再次显示初始值。 _tia rene
_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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.