Validating Editors
- 2 minutes to read
When an end-user modifies a focused cell's value and tries to save the changes (by pressing the ENTER key or moving focus to another cell), the grid validates a new value. First, this value is validated by the editor itself. Then, the column's GridColumn.Validate event is raised, allowing you to manually validate the cell's value. Note, this event is not fired when changing cell values in code.
Validating a New Value
The event parameter's Value property returns the focused cell's new value, which should be validated. The old value is returned by the CellValue property. If a new value meets the validation rules, set the event parameter's IsValid property to true. Otherwise, if the focused cell's value is invalid, correct it and reassign it to the Value property, or set the IsValid property to false. In this instance, the cell focus cannot be moved to another cell until the cell's value is corrected.
Indicating Errors
If you've set the IsValid property to false, an error icon is displayed within an edited cell. Use the event parameter's ErrorType property, to specify the required icon. You can select an icon from the built-in icons (Information
, Critical
) or custom icons that can be supplied using the template (an icon's size must be 12x12 pixels).
<DataTemplate x:Key="{dxet:ErrorTypesThemeKey ResourceKey=Critical}">