System.Data Namespace DataColumnCollection Class
Removes the specified DataColumn object from the collection.
[ VB ]
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
);
- column
- The DataColumn to remove.
Exception Type |
Condition |
ArgumentNullException |
The column parameter is a null reference. |
ArgumentException |
The column does not belong to this collection, or the column is part of a relationship, or another column's compute expression depends on this column. |
Use this overloaded version of the Remove method to remove a specified DataColumn object from the DataColumnCollection.
To remove a column at a specified index, use the RemoveAt method. You can also use the Clear method to remove all members of the collection at once.
The CollectionChanged event occurs when a column is successfully removed from the collection.
The following example uses the CanRemove method to test whether the last column in a DataColumnCollection can be removed. If so, the Remove method is called to remove the column.
private void RemoveColumn ( DataTable myTable ) {
// get the DataColumnCollection.
DataColumnCollection myColumns = myTable.Columns;
DataColumn col = myColumns [ myColumns.Count -1 ];
if ( myColumns.CanRemove ( col ) ) myColumns.Remove ( col );
}
Private Sub RemoveColumn ( Dim myTable As DataTable )
' get the DataColumnCollection.
Dim myColumns As DataColumnCollection = myTable.Columns
Dim col As DataColumn = myColumns ( myColumns.Count -1 );
If myColumns.CanRemove ( col ) Then myColumns.Remove ( col );
End Sub |
|
C# |
VB |
DataColumnCollection Members DataColumnCollection.Remove Overload List Contains CanRemove Item