DataRowCollection.RemoveAt(Int32) 方法

定義

從集合的指定索引處移除資料列。Removes the row at the specified index from the collection.

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

參數

index
Int32

要移除之資料列的索引。The index of the row to remove.

範例

下列範例會藉由呼叫方法,移除中的最後一個資料列 DataRowCollection RemoveAtThe following example removes the last row in a DataRowCollection by calling the RemoveAt method.

 Private Sub RemoveRowByIndex()
    Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)
    Dim rowCollection As DataRowCollection = table.Rows
    If rowCollection.Count = 0 Then 
        Exit Sub
    End If
    rowCollection.RemoveAt(rowCollection.Count - 1)
End Sub

備註

移除資料列時,該資料列中的所有資料都會遺失。When a row is removed, all data in that row is lost. 您也可以呼叫 Delete 類別的方法 DataRow ,只將資料列標示為移除。You can also call the Delete method of the DataRow class to just mark a row for removal. 呼叫等同于 RemoveAt 呼叫 Delete ,然後再呼叫 AcceptChangesCalling RemoveAt is the same as calling Delete and then calling AcceptChanges.

您可以使用 Clear 方法,一次移除集合的所有成員。You can use the Clear method to remove all members of the collection at one time.

適用於

另請參閱