次の方法で共有


DataTable.RowChanged イベント

DataRow が正常に変更された後に発生します。

Public Event RowChanged As DataRowChangeEventHandler
[C#]
public event DataRowChangeEventHandler RowChanged;
[C++]
public: __event DataRowChangeEventHandler* RowChanged;

[JScript] JScript では、このクラスで定義されているイベントを処理できます。ただし、独自に定義することはできません。

イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、DataRowChangeEventArgs 型の引数を受け取りました。次の DataRowChangeEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ 説明
Action DataRow で実行されたアクションを取得します。
Row アクションが実行された行を取得します。

解説

詳細については、「 DataTable イベントの使用 」を参照してください。

使用例

 
Private Shared Sub DataTableRowChanged()
    Dim custTable As DataTable = New DataTable("Customers")
    ' add columns
    custTable.Columns.Add( "id", Type.GetType("System.Int32") )
    custTable.Columns.Add( "name", Type.GetType("System.String") )
    custTable.Columns.Add( "address", Type.GetType("System.String") )

    ' set PrimaryKey
    custTable.Columns( "id" ).Unique = true
    custTable.PrimaryKey = New DataColumn() { custTable.Columns("id") }

    ' add a RowChanged event handler for the table.
    AddHandler custTable.RowChanged, New DataRowChangeEventHandler( AddressOf Row_Changed )


    ' add ten rows
    Dim id As Integer
    For id = 1 To 10
        custTable.Rows.Add( _
            New Object() { id, string.Format("customer{0}", id), string.Format("address{0}", id) } )
    Next
    
    custTable.AcceptChanges()

    ' change the name column in all the rows
    Dim row As DataRow
    For Each row In custTable.Rows 
        row("name") = string.Format( "vip{0}", row("id") )
    Next

End Sub

Private Shared Sub Row_Changed(sender As Object, e As DataRowChangeEventArgs)
    Console.WriteLine( "Row_Changed Event: name={0}; action={1}", _
        e.Row("name"), e.Action) 
End Sub

[C#] 
private static void DataTableRowChanged()
{
    DataTable custTable = new DataTable("Customers");
    // add columns
    custTable.Columns.Add( "id", typeof(int) );
    custTable.Columns.Add( "name", typeof(string) );
    custTable.Columns.Add( "address", typeof(string) );

    // set PrimaryKey
    custTable.Columns[ "id" ].Unique = true;
    custTable.PrimaryKey = new DataColumn[] { custTable.Columns["id"] };

    // add a RowChanged event handler for the table.
    custTable.RowChanged += new DataRowChangeEventHandler( Row_Changed );


    // add ten rows
    for( int id=1; id<=10; id++ )
    {
        custTable.Rows.Add( 
            new object[] { id, string.Format("customer{0}", id), string.Format("address{0}", id) } );
    }
    
    custTable.AcceptChanges();

    // change the name column in all the rows
    foreach( DataRow row in custTable.Rows )
    {
        row["name"] = string.Format( "vip{0}", row["id"] );
    }

}

private static void Row_Changed( object sender, DataRowChangeEventArgs e )
{
    Console.WriteLine( "Row_Changed Event: name={0}; action={1}", 
        e.Row["name"], e.Action );
}

[C++] 

public:
    static void DataTableRowChanged() {
    DataTable* custTable = new DataTable(S"Customers");
    // add columns
    custTable->Columns->Add(S"id", __typeof(int));
    custTable->Columns->Add(S"name", __typeof(String));
    custTable->Columns->Add(S"address", __typeof(String));

    // set PrimaryKey
    custTable->Columns->Item[ S"id" ]->Unique = true;
    DataColumn* ColumnArray[] = { custTable->Columns->Item[S"id"] };
    custTable->PrimaryKey = ColumnArray;

    // add a RowChanged event handler for the table.
    custTable->RowChanged += new DataRowChangeEventHandler(0, Row_Changed);


    // add ten rows
    for (int id=1; id<=10; id++) {
        Object* temp0 [] = {__box(id), String::Format(S"customer {0}", __box(id)), String::Format(S"address {0}", __box(id)) };
        custTable->Rows->Add(temp0);
    }

    custTable->AcceptChanges();

    // change the name column in all the rows
    System::Collections::IEnumerator* myEnum = custTable->Rows->GetEnumerator();
        while (myEnum->MoveNext()) {
        DataRow* row = __try_cast<DataRow*>(myEnum->Current);
        row->Item[S"name"] = String::Format(S"vip {0}", row->Item[S"id"]);
    }
}

public:
    static void Row_Changed(Object* sender, System::Data::DataRowChangeEventArgs* e) {
        Console::WriteLine(S"Row_Changed Event: name= {0}; action= {1}",
        e->Row->Item[S"name"],__box( e->Action));
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataTable クラス | DataTable メンバ | System.Data 名前空間