Skip to main content

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
CellValue Gets the cell’s old valid value.
Column Gets the column that contains the processed cell.
ErrorContent Gets or sets an object that describes the validation error. Inherited from ValidationEventArgs.
ErrorType Gets or sets the error icon type. Inherited from ValidationEventArgs.
IsValid Gets or sets a value which specifies whether the value is valid. Inherited from ValidationEventArgs.
Row Gets the processed row. Inherited from GridRowValidationEventArgs.
RowHandle Gets the processed row’s handle. Inherited from GridRowValidationEventArgs.
UpdateSource Gets the action that caused the validation. Inherited from ValidationEventArgs.
Value Gets the editor’s value. Inherited from ValidationEventArgs.

The event data class exposes the following methods:

Method Description
SetError(Object, ErrorType) Marks the processed input value as invalid and displays an error within the editor with the specified error icon type. Inherited from ValidationEventArgs.
SetError(Object) Marks the processed input value as invalid and displays an error within the editor. Inherited from ValidationEventArgs.

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:

  1. Handle the column’s ColumnBase.Validate event.

  2. 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.

  3. Use the e.ErrorType and e.ErrorContent properties to specify an icon and an error description.

DevExpress WinUI Grid - ColumnBase Validate

<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.

See Also