This documentation is archived and is not being maintained.

DataTable.RowDeleted Event

Occurs after a row in the table has been deleted.

[Visual Basic]
Public Event RowDeleted As DataRowChangeEventHandler
public event DataRowChangeEventHandler RowDeleted;
public: __event DataRowChangeEventHandler* RowDeleted;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type DataRowChangeEventArgs containing data related to this event. The following DataRowChangeEventArgs properties provide information specific to this event.

Property Description
Action Gets the action that has occurred on a DataRow.
Row Gets the row upon which an action has occurred.


For more information see Working with DataTable Events.


[Visual Basic] 
Private Shared Sub DataTableRowDeleted()
    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 RowDeleted event handler for the table.
    AddHandler custTable.RowDeleted, New DataRowChangeEventHandler( AddressOf Row_Deleted )

    ' 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) } )

    ' Delete all the rows
    Dim row As DataRow
    For Each row In custTable.Rows 
End Sub

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

private static void DataTableRowDeleted()
    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 RowDeleted event handler for the table.
    custTable.RowDeleted += new DataRowChangeEventHandler( Row_Deleted );

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

    // Delete all the rows
    foreach( DataRow row in custTable.Rows )

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


static void DataTableRowDeleted() {
    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 RowDeleted event handler for the table.
    custTable->RowDeleted += new DataRowChangeEventHandler(0, Row_Deleted);

    // 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)) };


    // Delete all the rows
    System::Collections::IEnumerator* myEnum = custTable->Rows->GetEnumerator();
    while (myEnum->MoveNext()) {
        DataRow* row = __try_cast<DataRow*>(myEnum->Current);

static void Row_Deleted(Object* sender, DataRowChangeEventArgs* e) {
    Console::WriteLine(S"Row_Deleted Event: name= {0}; action= {1}",
    e->Row->Item[S"name", static_cast<int>(DataRowVersion::Original), e->Action]);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataTable Class | DataTable Members | System.Data Namespace