Share via


ListChangedEventArgs.NewIndex Properti

Definisi

Mendapatkan indeks item yang terpengaruh oleh perubahan.

public:
 property int NewIndex { int get(); };
public int NewIndex { get; }
member this.NewIndex : int
Public ReadOnly Property NewIndex As Integer

Nilai Properti

Indeks yang terpengaruh oleh perubahan.

Contoh

Contoh kode berikut menunjukkan penggunaan anggota ini. Dalam contoh, penanganan aktivitas melaporkan kemunculan BindingSource.ListChanged peristiwa. Laporan ini membantu Anda mempelajari kapan peristiwa terjadi dan dapat membantu Anda dalam penelusuran kesalahan. Untuk melaporkan beberapa peristiwa atau peristiwa yang sering terjadi, pertimbangkan untuk mengganti MessageBox.Show dengan Console.WriteLine atau menambahkan pesan ke multibaris TextBox.

Untuk menjalankan kode contoh, tempelkan ke dalam proyek yang berisi instans jenis BindingSource bernama BindingSource1. Kemudian pastikan bahwa penanganan aktivitas dikaitkan dengan peristiwa.BindingSource.ListChanged

private void BindingSource1_ListChanged(Object sender, ListChangedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ListChangedType", e.ListChangedType );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "NewIndex", e.NewIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "OldIndex", e.OldIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "PropertyDescriptor", e.PropertyDescriptor );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ListChanged Event" );
}
Private Sub BindingSource1_ListChanged(sender as Object, e as ListChangedEventArgs) _ 
     Handles BindingSource1.ListChanged

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ListChangedType", e.ListChangedType)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "NewIndex", e.NewIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "OldIndex", e.OldIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "PropertyDescriptor", e.PropertyDescriptor)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"ListChanged Event")

End Sub

Keterangan

Untuk item yang telah dipindahkan, properti ini mewakili lokasi baru item.

Berlaku untuk

Lihat juga