Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CurrencyManager.ItemChanged Event

Occurs when the current item has been altered.

[Visual Basic]
Public Event ItemChanged As ItemChangedEventHandler
[C#]
public event ItemChangedEventHandler ItemChanged;
[C++]
public: __event ItemChangedEventHandler* ItemChanged;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type ItemChangedEventArgs containing data related to this event. The following ItemChangedEventArgs property provides information specific to this event.

Property Description
Index Indicates the position of the item being changed within the list.

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 shouldn't 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.

Note   If you are creating your own control that uses the CurrencyManager, you should use the ListChanged event of the IBindingList class instead of the ItemChanged event. The ListChangedType property of the ListChangedEventArgs object enables you to determine the type of action that has occurred.

Example

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

[Visual Basic] 
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

[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);
}

[C++] 
private:
    void BindControl(DataTable* myTable)
    {
        // Bind A TextBox control to a DataTable column in a DataSet.
        textBox1->DataBindings->Add(S"Text", myTable, S"CompanyName");
        // Specify the CurrencyManager for the DataTable.
        myCurrencyManager = dynamic_cast<CurrencyManager*>(this->BindingContext->get_Item(myTable, S""));
        // Add event handlers.
        myCurrencyManager->ItemChanged+=
            new ItemChangedEventHandler(this, &Form1::CurrencyManager_ItemChanged);
        myCurrencyManager->PositionChanged+= 
            new 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(S"Position Changed {0}", __box(myCurrencyManager->Position));
    }

    void CurrencyManager_ItemChanged(Object* sender, System::Windows::Forms::ItemChangedEventArgs* /*e*/){
        CurrencyManager* myCurrencyManager = dynamic_cast<CurrencyManager*> (sender);
        Console::WriteLine(S"Item Changed {0}", __box(myCurrencyManager->Position));
    }

[JScript] 
private function BindControl(myTable : 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 = CurrencyManager(this.BindingContext[myTable, ""]);
    // Add event handlers.
    myCurrencyManager.add_ItemChanged(CurrencyManager_ItemChanged);
    myCurrencyManager.add_PositionChanged(CurrencyManager_PositionChanged);
    // Set the initial Position of the control.
    myCurrencyManager.Position = 0;
}
 
private function CurrencyManager_PositionChanged(sender, e : System.EventArgs){
    var myCurrencyManager : CurrencyManager = CurrencyManager(sender);
    Console.WriteLine("Position Changed " + myCurrencyManager.Position);
}

private function CurrencyManager_ItemChanged(sender, e : System.Windows.Forms.ItemChangedEventArgs){
    var myCurrencyManager : CurrencyManager = CurrencyManager(sender);
    Console.WriteLine("Item Changed " + myCurrencyManager.Position);
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

CurrencyManager Class | CurrencyManager Members | System.Windows.Forms Namespace | PositionChanged

Show:
© 2015 Microsoft