System.Data Namespace DataColumnCollection Class
Occurs when the columns collection changes, either by adding or removing a column.
[ VB ]
Public Event CollectionChanged As CollectionChangeEventHandler
[ C# ]
public event CollectionChangeEventHandler CollectionChanged;
[ C++ ]
public: __event CollectionChangeEventHandler* CollectionChanged;
[ JScript ] In JScript, you can handle the events defined by a class, but you cannot define your own.
The event handler receives a CollectionChangeEventArgs containing data related to the CollectionChanged event. The following CollectionChangeEventArgs properties provide information specific to this event.
Property |
Description |
Action |
Gets an action that specifies how the collection changed. |
Element |
Gets the instance of the collection with the change. |
The Contains and CanRemove methods can be used to determine if a column exists and can be removed.
The following example adds an event handler for the CollectionChanged event.
private void AddHandler ( DataTable myTable ) {
DataColumnCollection cols=myTable.Columns;
cols.CollectionChanged +=
new System.ComponentModel.CollectionChangeEventHandler (
DataColumnCollection_Changed );
}
private void DataColumnCollection_Changed ( object sender,
System.ComponentModel.CollectionChangeEventArgs e ) {
DataColumnCollection cols= ( DataColumnCollection ) sender;
Response.Write ( "DataColumnCollectionChanged: " + cols.Count );
}
DataColumnCollection Members