Export (0) Print
Expand All

DataColumnCollection.RemoveAt Method

Removes the column at the specified index from the collection.

[Visual Basic]
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
);

Parameters

index
The index of the column to remove.

Exceptions

Exception Type Condition
ArgumentException The collection does not have a column at the specified index.

Remarks

If the collection is successfully changed by adding or removing columns, the OnCollectionChanged event occurs.

Example

[Visual Basic] 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 RemoveAt method.

[Visual Basic] 
Private Sub RemoveColumnAtIndex(thisIndex As Integer)
   Dim cols As DataColumnCollection
   ' Get the DataColumnCollection from a DataTable in a DataSet.
   cols = DataSet1.Tables("Orders").Columns
   If cols.CanRemove(cols(thisIndex)) Then 
      cols.RemoveAt(thisIndex)
   End If
End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumnCollection Class | DataColumnCollection Members | System.Data Namespace | IndexOf | Contains | CanRemove

Show:
© 2014 Microsoft