Back to Devexpress

Attribute-Based Validation

wpf-9770-controls-and-libraries-data-grid-data-editing-and-validation-input-validation-attribute-based-validation.md

latest3.1 KB
Original Source

Attribute-Based Validation

  • Jan 08, 2023

The GridControl supports DataAnnotations attributes that specify data validation rules. You should reference the System.ComponentModel.DataAnnotations assembly to use data annotation attributes.

View Example: How to Implement Attributes-Based Validation

Data Annotation Attributes

Validation AttributeDescription
CustomValidationAttributeSpecifies a custom validation method.
DataTypeAttributeSpecifies a particular data type, such as an e-mail address or a phone number.
EnumDataTypeAttributeEnsures that the value exists in an enumeration.
RangeAttributeDesignates minimum and maximum constraints.
RegularExpressionAttributeUses a regular expression to determine valid values.
RequiredAttributeSpecifies that a value must be provided.
StringLengthAttributeDesignates maximum and minimum number of characters.

Default Behavior

The GridControl displays error icons ( ) within cells with invalid values, and provides error descriptions displayed as tooltips. In this case, you cannot focus another cell until the cell’s value is corrected:

Run Demo: Data Validation

Custom Validation

The following validation options allow you to override default behavior:

|

Validation Attribute

|

Description

| | --- | --- | |

ColumnBase.ShowValidationAttributeErrors

DataViewBase.ShowValidationAttributeErrors

|

If set to false , hides validation errors specified via DataAnnotations attributes.

| |

DataViewBase.AllowCommitOnValidationAttributeError

|

If set to true , posts the invalid value to a data source and allows the cell focus to be moved to another cell.

|

Limitations

The attributes-based validation does not work when you use the ColumnBase.Binding property.