Removes the specified DataColumn from the collection.
[Visual Basic] Overloads Public Sub Remove( _ ByVal column As DataColumn _ ) [C#] public void Remove( DataColumn column ); [C++] public: void Remove( DataColumn* column ); [JScript] public function Remove( column : DataColumn );
Exception Type | Condition |
---|---|
ArgumentNullException | The column parameter is a null reference (in Visual Basic Nothing). |
ArgumentException | The column doesn't belong to this collection.
-Or- The column is part of a relationship. -Or- Another column's compute expression depends on this column. |
If the collection is succesfully changed by adding or removing columns, the OnCollectionChanged event occurs.
The following example uses the Contains method to determine if a named column exists. If so, the Item property (ColumnsCollection indexer) returns the column. The CanRemove method then checks whether the column can be removed; if so, the Remove method removes it.
[Visual Basic]
Private Sub TestAndRemove(removedCol As DataColumn) Dim cols As ColumnsCollection ' Get the ColumnsCollection from a DataTable in a DataSet. cols = DataSet1.Tables("Orders").Columns If cols.Contains(removedCol.ColumnName) Then cols.Remove(removedCol) End If End Sub If cols.CanRemove(removedCol) Then cols.Remove(removedCol) End If DataGrid1.PopulateColumns
ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Remove Overload List | Contains | CanRemove | Item