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の呼び出しは、Deleteを呼び出してからAcceptChangesを呼び出すのと同じです。

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

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

適用対象

こちらもご覧ください