Removes a column from the collection.
Removes the column at the specified index from the collection.
[Visual Basic] Overloads Public Sub Remove(Integer)
[C#] public void Remove(int);
[C++] public: void Remove(int);
[JScript] public function Remove(int);
Removes the column with the specified name from the collection.
[Visual Basic] Overloads Public Sub Remove(String)
[C#] public void Remove(String);
[C++] public: void Remove(String*);
[JScript] public function Remove(String);
Removes the specified DataColumn from the collection.
[Visual Basic] Overloads Public Sub Remove(DataColumn)
[C#] public void Remove(DataColumn);
[C++] public: void Remove(DataColumn*);
[JScript] public function Remove(DataColumn);
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.
Note This example shows how to use one of the overloaded versions of Remove. For other examples that may be available, see the individual overload topics.
[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