BindingSource.ResetItem(Int32) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menyebabkan kontrol yang terikat ke BindingSource untuk dibaca ulang item pada indeks yang ditentukan, dan menyegarkan nilai yang ditampilkan.
public:
void ResetItem(int itemIndex);
public void ResetItem (int itemIndex);
member this.ResetItem : int -> unit
Public Sub ResetItem (itemIndex As Integer)
Parameter
- itemIndex
- Int32
Indeks berbasis nol dari item yang telah berubah.
Contoh
Contoh kode berikut menggunakan BindingSource komponen untuk mengikat daftar ke DataGridView kontrol. Daftar tidak menaikkan pemberitahuan perubahan, sehingga ResetItem metode pada BindingSource digunakan untuk menaikkan ListChanged peristiwa. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan dalam Cara: Menaikkan Pemberitahuan Perubahan Menggunakan Metode ResetItem BindingSource.
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Get a reference to the list from the BindingSource.
List< DemoCustomer^ >^ customerList =
static_cast<List< DemoCustomer^ >^>(
this->customersBindingSource->DataSource);
// Change the value of the CompanyName property for the
// first item in the list.
customerList->default[ 0 ]->CompanyName = L"Tailspin Toys";
// Call ResetItem to alert the BindingSource that the
// list has changed.
this->customersBindingSource->ResetItem( 0 );
}
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click(object sender, EventArgs e)
{
// Get a reference to the list from the BindingSource.
List<DemoCustomer> customerList =
this.customersBindingSource.DataSource as List<DemoCustomer>;
// Change the value of the CompanyName property for the
// first item in the list.
customerList[0].CompanyName = "Tailspin Toys";
// Call ResetItem to alert the BindingSource that the
// list has changed.
this.customersBindingSource.ResetItem(0);
}
' This event handler changes the value of the CompanyName
' property for the first item in the list.
Private Sub changeItemBtn_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles changeItemBtn.Click
' Get a reference to the list from the BindingSource.
Dim customerList As List(Of DemoCustomer) = _
CType(Me.customersBindingSource.DataSource, List(Of DemoCustomer))
' Change the value of the CompanyName property for the
' first item in the list.
customerList(0).CompanyName = "Tailspin Toys"
' Call ResetItem to alert the BindingSource that the
' list has changed.
Me.customersBindingSource.ResetItem(0)
End Sub
Keterangan
Metode ini ResetItem memberi tahu semua kontrol yang terikat ke item pada yang ditentukan untuk menyegarkan Position nilainya. Metode melakukan ini dengan menaikkan ListChanged peristiwa dengan ListChangedEventArgs.ListChangedType diatur ke ListChangedType.ItemChanged.
ResetItem secara otomatis dipanggil setiap kali perubahan dilakukan pada nilai item individual. Namun, programmer juga dapat memanggil metode ini secara eksplisit.