Partilhar via


DataColumnCollection.CollectionChanged Evento

Definição

Ocorre quando uma coleção de colunas é alterada, seja pela inclusão ou pela remoção de uma coluna.

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

Exemplos

O exemplo a seguir adiciona um manipulador de eventos para o 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

Comentários

Use os Contains métodos e CanRemove para determinar se uma coluna existe e pode ser removida.

Aplica-se a