Export (0) Print
Expand All

DataGrid.CancelEdit Method

Causes the data grid to cancel the current edit, restore the original value, and exit editing mode.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method CancelEdit() Causes the data grid to cancel the current edit, restore the original value, and exit editing mode.
Public method CancelEdit(DataGridEditingUnit) Causes the data grid to cancel the current edit, restore the original value, and exit editing mode.
Top

By default, you can edit items directly in the DataGrid. You manually cancel a cell edit by pressing ESC one time, and cancel all edits in a row by pressing ESC two times. To guarantee that edits can be committed and canceled correctly, the objects in the DataGrid must implement the IEditableObject interface. Alternatively, you can set the IsReadOnly property to true to disable editing in the DataGrid.

Caution note Caution:

If CancelEdit is called in client code before the editing element is loaded, an ArgumentNullException will occur at run time. This occurs because the CancelEdit method attempts to revert the value back to the unedited value, but the unedited value has not yet been set. To avoid this error, CancelEdit should only be called after the cell has been prepared for editing, for example, in the PreparingCellForEdit event handler.

Community Additions

ADD
Show:
© 2014 Microsoft