| [ Team LiB ] |
|
23.5 Events Reference
The ColumnChanged event is raised after the value for a column in the DataRow has been changed. ExampleThe following code demonstrates how to handle the ColumnChanged event: DataTable dt = new DataTable();
dt.ColumnChanged += new DataColumnChangeEventHandler(dt_ColumnChanged);
private void dt_ColumnChanged(object sender,
DataColumnChangeEventArgs e)
{
MessageBox.Show("ColumnChanged: Name = " + e.Column.ColumnName + "; " +
"ProposedValue = " + e.ProposedValue.ToString() + "; " +
"Row Id = " + e.Row["Id"].ToString());
}
NotesThe event handler receives an argument of type DataColumnChangeEventArgs containing properties that provide specific information about the event as described in Table 23-13.
The ColumnChanging event is raised when the value for column in the DataRow is being changed. ExampleThe following code demonstrates how to handle the ColumnChanging event: DataTable dt = new DataTable();
dt.ColumnChanging += new DataColumnChangeEventHandler(dt_ColumnChanging);
private void dt_ColumnChanging(object sender,
DataColumnChangeEventArgs e)
{
MessageBox.Show("ColumnChanging: Name = " + e.Column.ColumnName + "; " +
"ProposedValue = " + e.ProposedValue.ToString() + "; " +
"Row Id = " + e.Row["Id"].ToString());
}
NoteThe event handler receives an argument of type DataColumnChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-13.
The RowChanged event is raised after a DataRow is successfully changed. ExampleThe following code demonstrates how to handle the RowChanged event: DataTable dt = new DataTable();
dt.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);
private void dt_RowChanged(object sender,
DataRowChangeEventArgs e)
{
MessageBox.Show("RowChanged: Action = " + e.Action + "; " +
"Row Id = " + e.Row["Id"].ToString());
}
NotesThe event handler receives an argument of type DataRowChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-14. DataRowAction enumeration is covered in Table 23-15.
The RowChanging event is raised when a DataRow is about to be changed. ExampleThe following code demonstrates how to handle the RowChanging event: DataTable dt = new DataTable();
dt.RowChanging += new DataRowChangeEventHandler(dt_RowChanging);
private void dt_RowChanging(object sender,
DataRowChangeEventArgs e)
{
MessageBox.Show("RowChanging: Action = " + e.Action + "; " +
"Row Id = " + e.Row["Id"].ToString());
}
NoteThe event handler receives an argument of type DataRowChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-14.
The RowDeleted event is raised after a row is deleted from the table. ExampleThe following code demonstrates how to handle the RowDeleted event: DataTable dt = new DataTable();
dt.RowDeleted += new DataRowChangeEventHandler(dt_RowDeleted);
private void dt_RowDeleted(object sender,
DataRowChangeEventArgs e)
{
MessageBox.Show("RowDeleted: Action = " + e.Action + "; " +
"Row Id = " + e.Row["Id"].ToString());
}
NoteThe event handler receives an argument of type DataRowChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-14.
The RowDeleting event is raised when a row is about to be deleted from the table. ExampleThe following code demonstrates how to handle the RowDeleting event: DataTable dt = new DataTable();
dt.RowDeleting += new DataRowChangeEventHandler(dt_RowDeleting);
private void dt_RowDeleting(object sender,
DataRowChangeEventArgs e)
{
MessageBox.Show("RowDeleting: Action = " + e.Action + "; " +
"Row Id = " + e.Row["Id"].ToString());
}
NoteThe event handler receives an argument of type DataRowChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-14. |
| [ Team LiB ] |
|