将(对象的)列表绑定到DataRepeater的正确方法是什么?您能提供这方面的示例代码吗?
我一直在绞尽脑汁地思考这个问题,虽然我可以在中继器中显示一个已经填满的列表,但随后对列表的更改对DataRepeater没有任何影响。
最终,我希望用它来绑定到字典,如果可能的话,但我甚至不能让基本的工作在这里。
数据中继器被添加到表单设计图面上,在ItemTemplate中有3个标签和一个进度条。然后,我尝试设置列表和中继器的代码(其中DutData是DataRepeater)是:
Public Class BurnIn
Public Shared currentDuts As New Dictionary(Of UInteger, DeviceUnderTest) ' Collection of all current DUTs.
Dim bs As New BindingSource
Dim testTemp As Boolean = False
Dim testList As New List(Of DeviceUnderTest)
Private Sub BurnIn_Load() Handles Me.Load
'...
' Add two items to the dictionary and populate them
currentDuts.Add(0, New DeviceUnderTest(Me.user, 0))
currentDuts.Item(0).RackBay = "012345678901"
currentDuts.Item(0).AssemblySerial = "123456789"
currentDuts.Item(0).SetProgram(1, "Program1")
currentDuts.Add(currentDuts.Count, New DeviceUnderTest(Me.user, 1))
currentDuts.Item(1).RackBay = "109876543210"
currentDuts.Item(1).AssemblySerial = "1319A5126"
currentDuts.Item(1).SetProgram(1, "Program1")
' Copy the items to the test list.
testList.Add(currentDuts.Item(0))
testList.Add(currentDuts.Item(1))
testTemp = True
' Setup the binding source, data source and data bindings.
bs.DataSource = testList
LocationLabel.DataBindings.Add("Text", bs, "RackBay")
DutLabel.DataBindings.Add("Text", bs, "AssemblySerial")
ProgramLabel.DataBindings.Add("Text", bs, "Program")
DutProgress.DataBindings.Add("Value", bs, "Progress")
DutData.DataSource = testList
'...
Me.Show()
End Sub然后测试添加或删除列表项:
Private Sub Button1_Click() Handles Button1.Click
If testTemp = False Then
' Add an item to the dictionary and populate it.
currentDuts.Add(currentDuts.Count, New DeviceUnderTest(Me.user, 1))
currentDuts.Item(1).RackBay = "109876543210"
currentDuts.Item(1).AssemblySerial = "1319A5126"
currentDuts.Item(1).SetProgram(1, "Program1")
' Copy the item to the test list.
testList.Add(currentDuts.Item(1))
testTemp = True
Else
' Remove the item from the dictionary and the list.
currentDuts.Remove(1)
testList.Remove(testList.Item(1))
testTemp = False
End If
End Sub
End Class发布于 2013-08-23 09:46:21
第一件事是用BindingList替换列表
Dim testList As New BindingList(Of DeviceUnderTest)https://stackoverflow.com/questions/18399238
复制相似问题