System.Data Namespace DataColumnCollection Class
Removes the column at the given index.
[ VB ]
Public Sub RemoveAt ( _
ByVal index As Integer _
)
[ C# ]
public void RemoveAt (
int index
);
[ C++ ]
public: void RemoveAt (
int index
);
[ JScript ]
public function RemoveAt (
index : int
);
- index
- The index of the column to remove.
Exception Type |
Condition |
ArgumentException |
The collection does not have a column at the specified index. |
Use the RemoveAt method to remove the DataColumn object at the specified index in the DataColumnCollection.
To remove a column with a specified name, use the Remove 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 RemoveAt 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.RemoveAt ( myColumns.Count -1 );
}
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.RemoveAt ( myColumns.Count -1 );
End Sub |
|
C# |
VB |
DataColumnCollection Members Add Clear Remove