首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使DataRepeater绑定到列表(对象)更新?

使DataRepeater绑定到列表(对象)更新?
EN

Stack Overflow用户
提问于 2013-08-23 09:20:44
回答 1查看 1K关注 0票数 0

将(对象的)列表绑定到DataRepeater的正确方法是什么?您能提供这方面的示例代码吗?

我一直在绞尽脑汁地思考这个问题,虽然我可以在中继器中显示一个已经填满的列表,但随后对列表的更改对DataRepeater没有任何影响。

最终,我希望用它来绑定到字典,如果可能的话,但我甚至不能让基本的工作在这里。

数据中继器被添加到表单设计图面上,在ItemTemplate中有3个标签和一个进度条。然后,我尝试设置列表和中继器的代码(其中DutData是DataRepeater)是:

代码语言:javascript
复制
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

然后测试添加或删除列表项:

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-23 09:46:21

第一件事是用BindingList替换列表

代码语言:javascript
复制
Dim testList As New BindingList(Of DeviceUnderTest)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18399238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档