Skip to main content

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

View Example: How to Implement Attributes-Based Validation

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

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.