ItemTemplate に Label1 と Button1 を持つ DataRepeater1 があります。これら 3 つのコントロールは BindingList(Of T) にバインドされます。ここで、T は atm であり、単一の文字列プロパティを持つ非常に単純なクラスです。
ユーザーが DataRepeater アイテムのボタンの 1 つをクリックすると、バインドされたデータ リスト内の文字列が更新されます。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