CurrencyManager.ItemChanged Event

Definition

Occurs when the current item has been altered.

C#
public event System.Windows.Forms.ItemChangedEventHandler ItemChanged;
C#
public event System.Windows.Forms.ItemChangedEventHandler? ItemChanged;

Event Type

Examples

The following code example adds event handlers for the ItemChanged and PositionChanged events.

C#
   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);
   }

Remarks

The ItemChanged event will occur when the user calls the ResumeBinding or SuspendBinding method.

The ItemChanged event occurs only when the item itself has been changed in some manner. For example, if the value of an item is changed from 10 to 42, the event will occur. 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. For example, if you change the value of a DataRowView, the ItemChanged event will occur.

Anteckning

If you are creating your own control that uses the CurrencyManager, you should use the IBindingList.ListChanged instead of the CurrencyManager.ItemChanged event. 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.

Applies to

Produkt Versioner
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also