CurrencyManager.ItemChanged CurrencyManager.ItemChanged CurrencyManager.ItemChanged CurrencyManager.ItemChanged Event

定义

在当前项更改后发生。Occurs when the current item has been altered.

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 

示例

下面的代码示例添加的事件处理程序ItemChangedPositionChanged事件。The following code example adds event handlers for the ItemChanged and PositionChanged events.

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 'BindControl


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 'CurrencyManager_PositionChanged


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 'CurrencyManager_ItemChanged

注解

ItemChanged在用户调用时,事件将会发生ResumeBindingSuspendBinding方法。The ItemChanged event will occur when the user calls the ResumeBinding or SuspendBinding method.

ItemChanged仅当项本身已更改以某种方式发生的事件。The ItemChanged event occurs only when the item itself has been changed in some manner. 例如,如果项的值从 10 更改为 42,会发生该事件。For example, if the value of an item is changed from 10 to 42, the event will occur. 不应与混淆这PositionChanged其中项已更改为新项的事件。This should not be confused with the PositionChanged event where the item has been changed to a new item.

如果基础数据发生更改,也会发生该事件。The event will also occur if the underlying data changes. 例如,如果您更改的值DataRowView,则ItemChanged事件发生一次。For example, if you change the value of a DataRowView, the ItemChanged event will occur.

备注

如果要创建您自己使用的控件CurrencyManager,则应使用IBindingList.ListChanged而不是CurrencyManager.ItemChanged事件。If you are creating your own control that uses the CurrencyManager, you should use the IBindingList.ListChanged instead of the CurrencyManager.ItemChanged event. ListChangedType属性的ListChangedEventArgs使您能够确定已发生的操作的类型。The ListChangedType property of the ListChangedEventArgs enables you to determine the type of action that has occurred.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于

另请参阅