Attributes-Based Validation
- 2 minutes to read
The GridControl supports DataAnnotations attributes that specify data validation rules (to use data annotation attributes, reference the System.ComponentModel.DataAnnotations assembly). These attributes are listed in the table below.
Validation Attribute | Description |
---|---|
CustomValidationAttribute | Uses a custom method for validation. |
DataTypeAttribute | Specifies a particular type of data, such as an e-mail address or 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. |
By default, the grid displays error icons () within cells with invalid values, and provides error descriptions displayed as tooltips (see the image below). In this instance, the cell focus cannot be moved to another cell until the cell’s value is corrected.
The following validation options allow you to override default behavior.
Validation Attribute | Description |
---|---|
If set to false, hides validation errors specified via DataAnnotations attributes. | |
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.