wpf-6606-controls-and-libraries-data-grid-data-editing-and-validation-modify-cell-values-inplace-editors.md
The GridControl uses in-place data editors to display and edit cell values:
Data editing is allowed if the DataViewBase.AllowEditing property is set to true and the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.Cell.
Individual columns have the ColumnBase.AllowEditing property. The property’s default value is Default - the View controls the column’s behavior. Set this property to true or false to override the default behavior. For example, you can set the column’s ColumnBase.AllowEditing property to false to prevent users from changing its values.
If the column’s ColumnBase.ReadOnly property is set to true:
Users can switch the GridControl to edit mode in the following ways:
This activates the focused cell’s in-place editor to allow an end user to modify the value.
To save the changes and close the editor, users should press Enter or move focus to another cell. The GridControl raises the GridViewBase.CellValueChanged event after changes are saved. Pressing Esc closes the editor and discards the changes.
The GridViewBase.ShowingEditor / TreeListView.ShowingEditor event is raised before the focused cell’s editor is activated and allows you to cancel the action. After the editor is shown, the GridControl raises the GridViewBase.ShownEditor / TreeListView.ShownEditor event.
To invoke the cell’s editor in code, focus the cell and call the DataViewBase.ShowEditor method. Refer to the Focusing topic for information on how to move cell and row focus.
The GridControl has two methods to hide the active editor:
| Method | Description |
|---|---|
| DataViewBase.CloseEditor | Hides the active editor and saves the changes. |
| DataViewBase.HideEditor | Hides the active editor and discards the changes. |
After the editor is closed, the GridControl raises the GridViewBase.HiddenEditor / TreeListView.HiddenEditor event.
A user can select a cell to initiate edit mode. The edit mode in the GridControl works on a per-row basis:
When the View is in edit mode, the DataViewBase.ActiveEditor property returns the edited cell’s editor and the DataViewBase.IsEditing property returns true.
Before the active editor’s new value is posted to a data source, it is validated. If a new value is valid, it is posted to a data source and the editor can be closed. Otherwise, if a new value is invalid, the active editor cannot be closed, and cell focus cannot be moved to another cell until its value is correct. Refer to the Cell Validation topic for more information.
The PostEditor() method validates and queues cell changes. The CommitEditing() method validates and posts changes made within the focused row.
The DataViewBase.GetIsEditorActivationAction property allows you to specify whether a user action (key press, text input, or left mouse button click) activates the focused editor. You can restrict the number of activation actions or activate editors based on a condition.
When a user activates an editor, the default behavior passes the activation action to the editor. Handle the DataViewBase.ProcessEditorActivationAction event to specify whether to pass the action to the editor.
The GridControl processes keys a user presses even if the editor is active. For example, arrow keys move focus between rows and cells. The DataViewBase.GetActiveEditorNeedsKey event allows you to specify keys that are processed by the active editor instead of the GridControl.
View Example: How to Specify Navigation in Custom Cell Editors
When a user changes a cell value, the value is posted to a data source after the user moves focus from the edited cell. To post the the value immediately after a user changes it, enable the DataViewBase.EnableImmediatePosting property.
View Example: Immediately Post New Cell Values
Note
The immediate posting functionality is not supported in the following scenarios:
Set the BaseColumn.EnableImmediatePosting property to true for an individual column to enable immediate posting for this column. If you set the BaseColumn.EnableImmediatePosting property to null, the column applies the DataViewBase.EnableImmediatePosting property’s value.
Handle the GridViewBase.CellValueChanging event and call the DataViewBase.PostEditor method in the event handler. Use this approach to implement complex logic.
The following code sample posts the Name column’s values:
<dxg:TableView CellValueChanging="CellValueChanging" />
void CellValueChanging(object sender, DevExpress.Xpf.Grid.CellValueChangedEventArgs e) {
if (e.Column.FieldName == "Name")
e.Source.PostEditor();
}
Private Sub CellValueChanging(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.CellValueChangedEventArgs)
If e.Column.FieldName = "Name" Then e.Source.PostEditor()
End Sub
The GridControl allows users to edit multiple selected cells at once.
To enable multiple cell edit, follow the steps below:
Set the SelectionMode property to one of the following values:
Set the TableView.MultiCellEditMode property to one of the following values:
To apply changes to multiple cells, take the following steps:
Select the range of cells. For more information, refer to the following help topic: Cell Selection.
In the selected range, focus a specific cell. To do this, left-click the cell with Shift pressed or right-click it.
Edit the focused cell.
Press Enter or move focus to post changes.
If you need to post changes immediately, set the DataViewBase.EnableImmediatePosting or BaseColumn.EnableImmediatePosting property to true. Refer to the following help topic for more information: Immediate Posting.
<dxg:GridControl ...
ItemsSource="{Binding Items}"
SelectionMode="Row">
<dxg:GridControl.View>
<dxg:TableView MultiCellEditMode="FocusedColumn"
EnableImmediatePosting="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
To restore values after a multi-cell edit operation, press Ctrl + Z (before changes are posted).
Row validation is not supported.
UpdateRowButtons is not supported (OnCellValueChange and OnCellEditorOpen).
Cell validation behaves as if the AllowLeaveInvalidEditor property is true. Note that the GridControl throws a warning exception if the MultiCellEditMode property is FocusedColumns or AllColumns and the AllowLeaveInvalidEditor property is false.
Users cannot update multiple cells when the New Item Row is focused.
AllColumns mode is not supported when SelectionMode is Row or MultipleRow.
If you have a column that displays Boolean values as check boxes, you can use the following properties to allow users to check/uncheck multiple check boxes at once:
Set the ColumnBase.ShowCheckBoxInHeader property to true to display a check box in the column header. This check box allows users to check/uncheck all check boxes in the column:
Assign a Boolean field name to the TableView.GroupRowCheckBoxFieldName property to display check boxes in group rows. Each group check box corresponds to check boxes displayed in the specified column and allows users to check/uncheck all check boxes in the group:
See Also