DataRowCollection.Remove(DataRow) メソッド

定義

指定された DataRow をコレクションから削除します。

public:
 void Remove(System::Data::DataRow ^ row);
public void Remove (System.Data.DataRow row);
member this.Remove : System.Data.DataRow -> unit
Public Sub Remove (row As DataRow)

パラメーター

row
DataRow

削除する DataRow

次の例では、 メソッドを Remove 使用して、オブジェクト内の見つかった行を DataRowCollection 削除します。 この例では、最初に メソッドを Contains 使用して、行コレクションに行が含まれているかどうかを判断します。 その場合は、 メソッドを Find 使用して特定の行を検索し、 メソッドを Remove 使用して行を削除します。

Private Sub RemoveFoundRow(ByVal table As DataTable)
    Dim rowCollection As DataRowCollection = table.Rows

    ' Test to see if the collection contains the value.
    If rowCollection.Contains(TextBox1.Text) Then
        Dim foundRow As DataRow = rowCollection.Find(TextBox1.Text)
        rowCollection.Remove(foundRow)
        Console.WriteLine("Row Deleted")
    Else
        Console.WriteLine("No such row found.")
    End If
 End Sub

注釈

行が削除されると、その行のすべてのデータが失われます。 クラスの メソッドを Delete 呼び出して、 DataRow 削除する行をマークすることもできます。 の呼び出し Remove は、 を呼び出してから を呼び出 DeleteAcceptChangesのと同じです。

Remove オブジェクトの反復処理 DataRowCollection 中に foreach ループでを呼び出さないでください。 Remove は、コレクションの状態を変更します。

メソッドを Clear 使用して、コレクションのすべてのメンバーを一度に削除することもできます。

適用対象

こちらもご覧ください