我可以使用此代码将组合框绑定到linq对象的属性(其中salesOrderHeader是我的linq对象,而CustomerId是属性):
cb_Customer.DataBindings.Add(New Binding("SelectedValue", salesOrderHeader, "CustomerId"))
但是,这仅在属性为整数数据类型时才有效。
当我尝试以下操作时,它无法正常工作,因为&order.3' orderCurrencyid'只是一个字节
cb_OrderCurrency.DataBindings.Add(New Binding("SelectedValue", salesOrderHeader, "orderCurrencyid"))
如何将LINQ对象中的非整数值绑定到组合框?
答案 0 :(得分:0)
感谢Fabio指出我正确的方向。
我设法通过更改我的组合框项目类来解决这个问题:
Public Class cbValues
Private mItemId As Integer
Private mItemName As String
Public Sub New(ItemId As Integer, ItemName As String)
mItemId = ItemId
mItemName = ItemName
End Sub
Public Property ItemId As Integer
Get
Return mItemId
End Get
Set(value As Integer)
mItemId = value
End Set
End Property
Public Property ItemName As String
Get
Return mItemName
End Get
Set(value As String)
mItemName = value
End Set
End Property
End Class
要
Public Class cbValues
Private mItemId As Object
Private mItemName As String
Public Sub New(ItemId As Object, ItemName As String)
mItemId = ItemId
mItemName = ItemName
End Sub
Public Property ItemId As Object
Get
Return mItemId
End Get
Set(value As Object)
mItemId = value
End Set
End Property
Public Property ItemName As String
Get
Return mItemName
End Get
Set(value As String)
mItemName = value
End Set
End Property
End Class
更改对象的所有整数引用,意味着它现在可以工作并绑定,无论ItemId属性的数据类型是什么。