DataTable.RowDeleted Event
Namespace
System.Data
Assembly
System.Data.dll
Summary
Occurs after a DataRow
has been deleted from a DataTable
.
Syntax
public event DataRowChangeEventHandler RowDeleted;
Applies To
- .NET Framework 2.0 and later
- .NET Core 2.0 and later
- .NET 5+
Remarks
The RowDeleted
event is raised after the DataRow
is removed from the DataTable
and its RowState
becomes Deleted
. It can be used to perform cleanup or logging tasks.
Example handlers can use the DataRowChangeEventArgs
parameter to get a reference to the deleted row.
Example
using System;
using System.Data;
class Program
{
static void Main()
{
DataTable table = new DataTable("Employees");
table.Columns.Add("Id", typeof(int));
table.Columns.Add("Name", typeof(string));
table.RowDeleted += Table_RowDeleted;
DataRow row = table.NewRow();
row["Id"] = 1;
row["Name"] = "Alice";
table.Rows.Add(row);
table.AcceptChanges();
row.Delete(); // Triggers RowDeleted event
}
private static void Table_RowDeleted(object sender, DataRowChangeEventArgs e)
{
Console.WriteLine($""Row deleted: Id={e.Row["Id"]}, Name={e.Row["Name"]}"");
}
}