DataRowView.CancelEdit Method

Definition

Cancels an edit procedure.

C#
public void CancelEdit();

Implements

Examples

The following example edits a row in a DataView. The CancelEdit method is called to cancel the changes if the validation fails.

C#
private void EditDataRowView(DataRowView rowView,
    string columnToEdit)
{
    rowView.BeginEdit();
    rowView[columnToEdit] = textBox1.Text;

    // Validate the input with a function.
    if (ValidateCompanyName(rowView[columnToEdit]))
        rowView.EndEdit();
    else
        rowView.CancelEdit();
}

private bool ValidateCompanyName(object valuetoCheck)
{
    // Insert code to validate the value.
    return true;
}

Remarks

After calling CancelEdit, all changes to the row are rolled back. You can also roll back changes by calling RejectChanges on the parent DataTable.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also