Bagikan melalui


CurrencyManager.ItemChanged Kejadian

Definisi

Terjadi ketika item saat ini telah diubah.

public:
 event System::Windows::Forms::ItemChangedEventHandler ^ ItemChanged;
public event System.Windows.Forms.ItemChangedEventHandler ItemChanged;
public event System.Windows.Forms.ItemChangedEventHandler? ItemChanged;
member this.ItemChanged : System.Windows.Forms.ItemChangedEventHandler 
Public Custom Event ItemChanged As ItemChangedEventHandler 

Jenis Acara

Contoh

Contoh kode berikut menambahkan penanganan aktivitas untuk ItemChanged peristiwa dan PositionChanged .

void BindControl( DataTable^ myTable )
{
   
   // Bind A TextBox control to a DataTable column in a DataSet.
   textBox1->DataBindings->Add( "Text", myTable, "CompanyName" );
   
   // Specify the CurrencyManager for the DataTable.
   myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[myTable, ""]);
   
   // Add event handlers.
   myCurrencyManager->ItemChanged += gcnew ItemChangedEventHandler( this, &Form1::CurrencyManager_ItemChanged );
   myCurrencyManager->PositionChanged += gcnew EventHandler( this, &Form1::CurrencyManager_PositionChanged );
   
   // Set the initial Position of the control.
   myCurrencyManager->Position = 0;
}

void CurrencyManager_PositionChanged( Object^ sender, System::EventArgs^ /*e*/ )
{
   CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(sender);
   Console::WriteLine( "Position Changed {0}", myCurrencyManager->Position );
}

void CurrencyManager_ItemChanged( Object^ sender, System::Windows::Forms::ItemChangedEventArgs^ /*e*/ )
{
   CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(sender);
   Console::WriteLine( "Item Changed {0}", myCurrencyManager->Position );
}
   private void BindControl(DataTable myTable)
   {
       // Bind A TextBox control to a DataTable column in a DataSet.
       textBox1.DataBindings.Add("Text", myTable, "CompanyName");
       // Specify the CurrencyManager for the DataTable.
       myCurrencyManager = (CurrencyManager)this.BindingContext[myTable, ""];
       // Add event handlers.
       myCurrencyManager.ItemChanged+=
       new ItemChangedEventHandler(CurrencyManager_ItemChanged);
       myCurrencyManager.PositionChanged+= 
       new EventHandler(CurrencyManager_PositionChanged);
       // Set the initial Position of the control.
       myCurrencyManager.Position = 0;
   }

   private void CurrencyManager_PositionChanged(object sender, System.EventArgs e){
       CurrencyManager myCurrencyManager = (CurrencyManager) sender;
       Console.WriteLine("Position Changed " + myCurrencyManager.Position);
   }

   private void CurrencyManager_ItemChanged(object sender, System.Windows.Forms.ItemChangedEventArgs e){
       CurrencyManager myCurrencyManager = (CurrencyManager) sender;
       Console.WriteLine("Item Changed " + myCurrencyManager.Position);
   }
Private Sub BindControl(myTable As DataTable)
    ' Bind A TextBox control to a DataTable column in a DataSet.
    textBox1.DataBindings.Add("Text", myTable, "CompanyName")
    ' Specify the CurrencyManager for the DataTable.
    myCurrencyManager = CType(Me.BindingContext(myTable, ""), CurrencyManager)
    ' Add event handlers.
    AddHandler myCurrencyManager.ItemChanged, AddressOf CurrencyManager_ItemChanged
    AddHandler myCurrencyManager.PositionChanged, AddressOf CurrencyManager_PositionChanged
    ' Set the initial Position of the control.
    myCurrencyManager.Position = 0
End Sub


Private Sub CurrencyManager_PositionChanged(sender As Object, e As System.EventArgs)
    Dim myCurrencyManager As CurrencyManager = CType(sender, CurrencyManager)
    Console.WriteLine(("Position Changed " & myCurrencyManager.Position))
End Sub


Private Sub CurrencyManager_ItemChanged(sender As Object, e As System.Windows.Forms.ItemChangedEventArgs)
    Dim myCurrencyManager As CurrencyManager = CType(sender, CurrencyManager)
    Console.WriteLine(("Item Changed " & myCurrencyManager.Position))
End Sub

Keterangan

Peristiwa ItemChanged akan terjadi ketika pengguna memanggil ResumeBinding metode atau SuspendBinding .

Peristiwa ItemChanged hanya terjadi ketika item itu sendiri telah diubah dengan cara tertentu. Misalnya, jika nilai item diubah dari 10 menjadi 42, peristiwa akan terjadi. Ini seharusnya tidak dikacaukan dengan PositionChanged peristiwa di mana item telah diubah menjadi item baru.

Peristiwa juga akan terjadi jika data yang mendasar berubah. Misalnya, jika Anda mengubah nilai DataRowView, ItemChanged peristiwa akan terjadi.

Catatan

Jika Anda membuat kontrol Anda sendiri yang menggunakan CurrencyManager, Anda harus menggunakan IBindingList.ListChanged alih-alih CurrencyManager.ItemChanged peristiwa. Properti ListChangedType memungkinkan ListChangedEventArgs Anda menentukan jenis tindakan yang telah terjadi.

Untuk informasi selengkapnya tentang menangani peristiwa, lihat Menangani dan Menaikkan Peristiwa.

Berlaku untuk

Lihat juga