ComponentOne DataObjects for .NET
Events on Adding Row
DataObjects for .NET (Enterprise Edition) > Business Logic > Business Logic Events > Events on Adding Row

Before adding a new row, DataObjects for .NET fires the BeforeAddNew event. When this event fires, the new row is not yet created. Throwing an exception in this event aborts the process of creating a new row and adding it to the table.

Once a new row has been created and filled with default values (see the field DefaultValue property), DataObjects for .NET fires the AfterAddNew event. That event can be used to fill default values of the fields according to some rules that cannot be specified as simple values of the DefaultValue property. It can also be used to specify the primary key values, see Keys Assigned by Client: New Row Detached and Attached State.

When a new row is created, it is empty, filled with default values, its primary key undefined. A row with an undefined primary key is in a special transitory state called detached. For more details, see Keys Assigned by Client: New Row Detached and Attached State. A row becomes a full-fledged table row (for example, it can be sent for updating the database) only after its primary key is set. There are two main scenarios in setting the new row primary key:

In both cases, the point in time when the row becomes a "regular", full-fledged row with a defined primary key value (becomes attached) is an event that is potentially important to the business logic. Before attaching a row, DataObjects for .NET fires the BeforeEndAddNew event. Throwing an exception in this event aborts the process of attaching the row (and aborts EndEdit, if the row is being attached as a result of an EndEdit call). After the row has been successfully attached, DataObjects for .NET fires the AfterEndAddNew event.

To inquire about the state of a newly added row, use the RowState property. For a detached newly added row the state is Detached. For an attached newly added row the state is Added.