DataColumnCollection.CollectionChanged 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於資料行集合變更時 (藉由加入或移除資料行)。
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
事件類型
範例
下列範例會新增 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
備註
Contains使用和 CanRemove 方法來判斷數據行是否存在且可移除。