我在 ItemTemplate 上有一个带有 Label1 和 Button1 的 DataRepeater1。这三个控件绑定到一个 BindingList(Of T),其中 T 是 atm,一个非常简单的类,它有一个字符串属性
当用户单击 DataRepeater 项的按钮之一时,它会更新绑定数据列表中的字符串。IE 如果用户单击DataRepeater 中第0 项上的按钮,则BindingList 中相同索引处的字符串会发生变化。
这有效
什么不起作用是在字符串更改之后,DataRepeater 应该更新相关项目的 Label1,因为它绑定到该字符串 - 但它没有。
谁能告诉我为什么??我当前的代码如下。谢谢
Imports System.ComponentModel
Public Class Form1
Class ListType
Public Sub New(newString As String)
Me.MyString = newString
End Sub
Public Property MyString As String
End Class
Dim MyList As New BindingList(Of ListType)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Bind BindingList to DataRepeater.
Label1.DataBindings.Add("Text", MyList, "MyString")
DataRepeater1.DataSource = MyList
' Add some items to the BindingList.
MyList.Add(New ListType("First"))
MyList.Add(New ListType("Second"))
MyList.Add(New ListType("Third"))
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Use the Index of the current item to change the string
' of the list item with the same index.
MyList(DataRepeater1.CurrentItemIndex).MyString = "Clicked"
' Show all the current list strings in a label outside of
' the DataRepeater.
Label2.Text = String.Empty
For Each Item As ListType In MyList
Label2.Text = Label2.Text & vbNewLine & Item.MyString
Next
End Sub
End Class