BeginEdit
DataRow.BeginEdit();
Puts the DataRow
into edit mode, suspending the
events that trigger validations rules.
The following example demonstrates how to use the BeginEdit( )
, EndEdit( )
, and CancelEdit( )
methods:
DataRow row; // ... retrieve data into the DataRow object row.BeginEdit(); foreach(DataColumn col in row.Table.Columns) { // ... modify the column value } Boolean rowValid = true; // check the values in the row to make sure that they are valid if(rowValid) { row.CancelEdit(); } else { row.EndEdit(); }
Updates to a row can be buffered by calling the BeginEdit( )
, EndEdit( )
, and CancelEdit( )
methods. The BeginEdit( )
method turns
off all constraints and suspends events used to enforce validation
rules. If CancelEdit( )
is called, the changes in
the buffer are discarded. When EndEdit( )
is
called, the data is validated against the constraints, and events are
raised if any violations occur.
Prior to calling EndEdit( )
, any changes made to
values for the row are stored as a proposed value. Until
EndEdit( )
is called, both the original value and
the proposed value can be retrieved by specifying
Original
or Proposed
as the
optional DataRowVersion
argument for the
Item
property. While the row is being edited, the
proposed value is returned by default.
The HasVersion
method can be called to determine
whether the row has an Original
or
Proposed
value.
BeginEdit( )
is called implicitly when a user
changes the value of a data-bound control.