ColumnBase.Validate Event
Enables you to validate the active editor’s value.
Namespace: DevExpress.WinUI.Grid
Assembly: DevExpress.WinUI.Grid.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
public event EventHandler<GridCellValidationEventArgs> Validate
#Event Data
The Validate event's data class is GridCellValidationEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cell |
Gets the cell’s old valid value. |
Column | Gets the column that contains the processed cell. |
Error |
Gets or sets an object that describes the validation error.
Inherited from Validation |
Error |
Gets or sets the error icon type.
Inherited from Validation |
Is |
Gets or sets a value which specifies whether the value is valid.
Inherited from Validation |
Row |
Gets the processed row.
Inherited from Grid |
Row |
Gets the processed row’s handle.
Inherited from Grid |
Update |
Gets the action that caused the validation.
Inherited from Validation |
Value |
Gets the editor’s value.
Inherited from Validation |
The event data class exposes the following methods:
Method | Description |
---|---|
Set |
Marks the processed input value as invalid and displays an error within the editor with the specified error icon type.
Inherited from Validation |
Set |
Marks the processed input value as invalid and displays an error within the editor.
Inherited from Validation |
#Remarks
When a user modifies a focused cell’s value and tries to save changes (presses the ENTER
key or moves focus to another cell), the GridControl validates a new value. First, this value is validated by the editor itself. Then, the GridControl raises the column’s ColumnBase.Validate
event. This event allows you to manually validate the cell’s value. The GridControl does not raise the ColumnBase.Validate
event when you change cell values in code.
To validate data in a specific column:
Handle the column’s
ColumnBase.Validate
event.Use the e.Value property to obtain an entered value that should be validated. If a cell’s value fails validation, set the e.IsValid property to false. In this case, a user cannot move focus to another cell until the cell’s value is valid. To disable this behavior, set the AllowLeaveInvalidEditor property to true.
Use the e.ErrorType and e.ErrorContent properties to specify an icon and an error description.
<dxg:GridControl ItemsSource="{x:Bind ViewModel.Source}"
AutoGenerateColumns="False"
NavigationStyle="Cell"
AllowLeaveInvalidEditor="True">
<dxg:GridControl.Columns>
<dxg:GridTextColumn FieldName="ProductName" Validate="GridTextColumn_Validate"/>
<dxg:GridTextColumn FieldName="Country"/>
<dxg:GridTextColumn FieldName="City"/>
<dxg:GridSpinEditColumn FieldName="UnitPrice"/>
<dxg:GridTextColumn FieldName="Quantity" />
</dxg:GridControl.Columns>
</dxg:GridControl>
void GridTextColumn_Validate(object sender, GridCellValidationEventArgs e) {
e.IsValid = (e.Value != null) && (e.Value.ToString().Length >= 3);
e.ErrorType = DevExpress.WinUI.Editors.ErrorType.Warning;
e.ErrorContent = "The product name must contain at least 3 characters.";
}
For more information, refer to the following help topic: Validate Data.