0

将 List(Of Object) 绑定到 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
4

1 回答 1

1

首先是用 BindingList 替换你的 List

Dim testList As New BindingList(Of DeviceUnderTest)
于 2013-08-23T09:46:21.283 回答