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 _
public void RemoveAt(
 int index
public: void RemoveAt(
 int index
public function RemoveAt(
   index : int


The index of the column to remove.


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


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


[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 
   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.


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

© 2014 Microsoft