Skip to main content
A newer version of this page is available. .

Attributes-Based Validation

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

Data Annotation Attributes

Validation Attribute Description
CustomValidationAttribute Specifies a custom validation method.
DataTypeAttribute Specifies a particular data type, such as an e-mail address or a phone number.
EnumDataTypeAttribute Ensures that the value exists in an enumeration.
RangeAttribute Designates minimum and maximum constraints.
RegularExpressionAttribute Uses a regular expression to determine valid values.
RequiredAttribute Specifies that a value must be provided.
StringLengthAttribute Designates maximum and minimum number of characters.

Default Behavior

The GridControl displays error icons (ErrorIcon_Critical) 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:

attributes-based validation

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.

Note

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

Refer to the How to: Implement Attributes-Based Validation example to learn more.