DataColumnCollection.CollectionChanged Evento

Definición

Se produce cuando la colección de columnas cambia, al agregar o quitar una columna.

public:
 event System::ComponentModel::CollectionChangeEventHandler ^ CollectionChanged;
public event System.ComponentModel.CollectionChangeEventHandler? CollectionChanged;
public event System.ComponentModel.CollectionChangeEventHandler CollectionChanged;
member this.CollectionChanged : System.ComponentModel.CollectionChangeEventHandler 
Public Custom Event CollectionChanged As CollectionChangeEventHandler 

Tipo de evento

Ejemplos

En el ejemplo siguiente se agrega un controlador de eventos para el evento CollectionChanged.

private void AddEventHandler(DataTable table)
{
    DataColumnCollection columns = table.Columns;
    columns.CollectionChanged += new
        System.ComponentModel.CollectionChangeEventHandler(
        ColumnsCollection_Changed);
}

private void ColumnsCollection_Changed(object sender,
    System.ComponentModel.CollectionChangeEventArgs e)
{
    DataColumnCollection columns =
        (DataColumnCollection) sender;
    Console.WriteLine("ColumnsCollectionChanged: "
        + columns.Count);
}
 Private Sub AddEventHandler(table As DataTable)
     Dim columns As DataColumnCollection = table.Columns
     AddHandler columns.CollectionChanged, _
        AddressOf ColumnsCollection_Changed
 End Sub    
    
 Private Sub ColumnsCollection_Changed _
    (sender As Object, e As System.ComponentModel. _
    CollectionChangeEventArgs)

     Dim columns As DataColumnCollection = _
        CType(sender, DataColumnCollection)
     Console.WriteLine("ColumnsCollectionChanged: " _
        & columns.Count.ToString())
End Sub

Comentarios

Use los Contains métodos y CanRemove para determinar si existe una columna y se puede quitar.

Se aplica a