This documentation is archived and is not being maintained.

DataRowCollection.RemoveAt Method

Removes the row 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 row to remove.


When a row is removed, all data in that row is lost. You can also call the Delete method of the DataRow class to simply mark a row for removal. Calling RemoveAt is the same as calling Delete and then calling AcceptChanges.

You can use the Clear method to remove all members of the collection at once.


[Visual Basic] The following example removes the last row in a DataRowCollection by calling the RemoveAt method.

[Visual Basic] 
Private Sub RemoveRowByIndex()
   Dim myTable As DataTable
   Dim rc As DataRowCollection
   Dim foundRow As DataRow
   myTable = CType(DataGrid1.DataSource, DataTable)
   rc = myTable.Rows
   If rc.Count = 0 Then Exit Sub
   rc.RemoveAt( rc.Count - 1)
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

DataRowCollection Class | DataRowCollection Members | System.Data Namespace | Clear | Add