DataRowCollection.RemoveAt(Int32) 方法

定義

從集合的指定索引處移除資料列。

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

參數

index
Int32

要移除之資料列的索引。

範例

下列範例會藉由呼叫 RemoveAt 方法,移除 中的DataRowCollection最後一個數據列。

 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

備註

拿掉資料列時,該數據列中的所有數據都會遺失。 您也可以呼叫 Delete 類別的 DataRow 方法,只標記要移除的數據列。 呼叫 RemoveAt 與呼叫 Delete 相同,然後呼叫 AcceptChanges

您可以使用 Clear 方法一次移除集合的所有成員。

適用於

另請參閱