Begins an edit operation on a DataRow object.
[Visual Basic] Public Sub BeginEdit() [C#] public void BeginEdit(); [C++] public: void BeginEdit(); [JScript] public function BeginEdit();
Exception Type | Condition |
---|---|
InRowChangingEventException | The method was called inside the RowChanging event. |
DeletedRowInaccessibleException | The method was called upon a deleted row. |
You can only create or update a row after calling the BeginEdit method; similarly, the EndEdit method must be called to commit the edit. (The BeginEdit method is called implicitly when the user changes the value of a databound control; the EndEdit method is called implicitly when you invoke the DataTable object's AcceptChanges method.) While in this edit mode, the DataRow stores representations of the original and new proposed values Therefore, as long as the EndEdit method has not been called, you can retrieve either the original or proposed version by passing either DataRowVersion.Original or DataRowVersion.Proposed for the version parameter of the Item property (DataRow indexer). You can also cancel any edits at this time by invoking the CancelEdit method.
To see if the row contains an original or proposed value, call the HasVersion method.
The following example edits the value of one column in the last row of a System.WinForms.DataGrid control. The example uses the BeginEdit, EndEdit, and AcceptChanges methods to programmatically edit the column's value and commit the change to the row, and finally to the table itself.
[Visual Basic]
Private Sub EditAndAccept() Dim t As DataTable t = DataGrid1.DataGridTable.DataTable Dim myrow As DataRow myRow = t.Rows(t.Rows.Count - 1) myrow.BeginEdit myrow(1) = Edit1.Text myrow.EndEdit myrow.AcceptChanges t.AcceptChanges End Sub
DataRow Class | DataRow Members | System.Data Namespace | AcceptChanges | CancelEdit | EndEdit | HasVersion | Item | RowState