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 使用して、コレクションのすべてのメンバーを一度に削除することもできます。

適用対象

こちらもご覧ください