Removes the column at the specified index from the collection.
[Visual Basic] Overloads Public Sub Remove( _ ByVal index As Integer _ ) [C#] public void Remove( int index ); [C++] public: void Remove( int index ); [JScript] public function Remove( index : int );
Exception Type | Condition |
---|---|
IndexOutOfRangeException | The collection doesn't have a column at this index. |
If the collection is succesfully changed by adding or removing columns, the OnCollectionChanged event occurs.
The following example first uses the Contains method to determine if a particular column is found in the collection. If it is found, the CanRemove method tests whether the column can be removed. If so, the column is removed with the Remove method.
[Visual Basic]
Private Sub RemoveColumnAtIndex(thisIndex As Integer) Dim cols As ColumnsCollection ' Get the ColumnsCollection from a DataTable in a DataSet. cols = DataSet1.Tables("Orders").Columns If cols.Contains(thisIndex) Then If cols.CanRemove(cols(thisIndex)) Then cols.Remove(thisIndex) End If End If
ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Remove Overload List | IndexOf | Contains | CanRemove