Xceed Grid for WinForms v4.3 Documentation
Editing
Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Editing

At runtime, Xceed Grid for WinForms provides the possibility to visually edit the content of each cell in the grid.

Entering edit mode

There are multiple ways to enter edit mode: Calling the EnterEdit method, in code, of the cell whose content is to be edited or selecting the cell to edit using the mouse or the keyboard and pressing the F2 key (or clicking a second time in the cell). 

Using the EnterEdit method will invoke the cell's editor (which is ambient on its parent column) and raise the EnteringEdit event. In the EnteringEdit event, it is possible to change the cell editor that will be used to edit the content of the cell or prevent the user from entering into edit mode.

Leaving edit mode

The modifications made to a cell's content can be committed or discarded using either the LeaveEdit method, in code, by using the keyboard or clicking somewhere else in the grid. 

In code, to commit the changes made to a cell's content, the LeaveEdit method must be called and its commit parameter set to true. To discard the changes, the same method must be called, but with its parameter set to false. Calling the LeaveEdit method with commit set to true will also raise the LeavingEdit event in which you can also cancel the modifications made to the cell's content or change the value that is about to be committed. 

When using the keyboard to commit or discard the modifications made to a cell's content, the Escape and Tab keys can be used. Pressing the Tab key will commit the changes while pressing the Escape key will discard the changes. Pressing Enter will commit the changes made to the current cell as well as all the modifications made to the cell's parent row. 

Keep in mind that the data source is not automatically updated when editing the grid. For example, if the data source is a dataset, only the in-memory data will be updated. It is up to you to update the physical data source. For information on how to update your data source, refer to the DataSet class topic in .NET Framework Class Library documentation.

Validation errors

By default, if a value is provided to a cell and it does not pass the validation process, the result is the equivalent of calling the LeaveEdit method with its commit parameter set to false: the new value will be discarded and the cell will leave edit mode. No exception will be thrown by the grid if a value fails validation. 

In order to change this behavior, the ValidationError event must be handled. In the ValidationError event, you can change the default behavior (leaving edit mode if value is not validated) by setting the CancelEdit property of the CellValidationErrorEventArgs to false.

Things you should consider

  • Do you want to prevent a cell, row or group from being edited? Set the corresponding grid element's ReadOnly property to true. 

  • Do you want to prevent every cell in the grid from being edited? Set the grid's ReadOnly property to true.