Partilhar via


CurrencyManager.ItemChanged Evento

Definição

Ocorre quando o item atual foi alterado.

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 

Tipo de evento

Exemplos

O exemplo de código a seguir adiciona manipuladores de eventos para os ItemChanged eventos e 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

Comentários

O ItemChanged evento ocorrerá quando o usuário chamar o ResumeBinding método ou SuspendBinding .

O ItemChanged evento ocorre somente quando o item em si foi alterado de alguma maneira. Por exemplo, se o valor de um item for alterado de 10 para 42, o evento ocorrerá. Isso não deve ser confundido com o PositionChanged evento em que o item foi alterado para um novo item.

O evento também ocorrerá se os dados subjacentes forem alterados. Por exemplo, se você alterar o valor de um DataRowView, o ItemChanged evento ocorrerá.

Observação

Se você estiver criando seu próprio controle que usa o CurrencyManager, deverá usar o IBindingList.ListChanged em vez do CurrencyManager.ItemChanged evento. A ListChangedType propriedade do ListChangedEventArgs permite determinar o tipo de ação que ocorreu.

Para obter mais informações sobre como lidar com eventos, consulte Manipulando e levantando eventos.

Aplica-se a

Confira também