DekGenius.com
[ Team LiB ] Previous Section Next Section

23.5 Events Reference

ColumnChanged

DataColumnChangeEventHandler ColumnChanged;

The ColumnChanged event is raised after the value for a column in the DataRow has been changed.

Example

The 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());
}

Notes

The event handler receives an argument of type DataColumnChangeEventArgs containing properties that provide specific information about the event as described in Table 23-13.

Table 23-13. DataColumnChangeEventArgs properties

Property

Description

Column

Returns a reference to the DataColumn that changes.

ProposedValue

Gets or sets a reference to an object representing the proposed value for the column.

Row

Returns a reference to the DataRow of the column that changes.

ColumnChanging

DataColumnChangeEventHandler ColumnChanging;

The ColumnChanging event is raised when the value for column in the DataRow is being changed.

Example

The 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());
}

Note

The event handler receives an argument of type DataColumnChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-13.

RowChanged

DataRowChangeEventHandler RowChanged;

The RowChanged event is raised after a DataRow is successfully changed.

Example

The 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());
}

Notes

The 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.

Table 23-14. DataRowChangeEventArgs properties

Property

Description

Action

Returns the action that has occurred on the DataRow. This value is from the DataRowAction enumeration as described in the next table.

Row

Returns a reference to the DataRow that is changing or being deleted.

Table 23-15. DataRowAction enumeration

Value

Description

Add

The row has been added to the table.

Change

The row has been modified.

Commit

The changes made to the row have been committed.

Delete

The row has been deleted from the table.

Nothing

The row has not been changed.

Rollback

The changes made to the row have been rolled back.

RowChanging

DataRowChangeEventHandler RowChanging;

The RowChanging event is raised when a DataRow is about to be changed.

Example

The 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());
}

Note

The event handler receives an argument of type DataRowChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-14.

RowDeleted

DataRowChangeEventHandler RowDeleted;

The RowDeleted event is raised after a row is deleted from the table.

Example

The 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());
}

Note

The event handler receives an argument of type DataRowChangeEventArgs, which contains properties that provide specific information about the event as described in Table 23-14.

RowDeleting

DataRowChangeEventHandler RowDeleting;

The RowDeleting event is raised when a row is about to be deleted from the table.

Example

The 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());
}

Note

The 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 ] Previous Section Next Section