[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Expand]Views
   [Expand]Grid View Data Layout
   [Expand]Binding to Data
   [Expand]Master-Detail Data Representation
   [Collapse]Data Editing and Validation
     Add and Remove Rows
    [Expand]Modify Cell Values
    [Collapse]Input Validation
      Cell Validation
      Row Validation
      Error Notification
      Attributes-Based Validation
    [Expand]Clipboard Management
     Examples
   [Expand]Grouping
   [Expand]Selection
   [Expand]Filtering and Searching
   [Expand]Sorting
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus and Navigation
   [Expand]Conditional Formatting
   [Expand]Drag-and-Drop
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Miscellaneous
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Attributes-Based Validation

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
System.ComponentModel.DataAnnotations.CustomValidationAttribute Uses a custom method for validation.
System.ComponentModel.DataAnnotations.DataTypeAttribute Specifies a particular type of data, such as an e-mail address or phone number.
System.ComponentModel.DataAnnotations.EnumDataTypeAttribute Ensures that the value exists in an enumeration.
System.ComponentModel.DataAnnotations.RangeAttribute Designates minimum and maximum constraints.
System.ComponentModel.DataAnnotations.RegularExpressionAttribute Uses a regular expression to determine valid values.
System.ComponentModel.DataAnnotations.RequiredAttribute Specifies that a value must be provided.
System.ComponentModel.DataAnnotations.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

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.

Is this topic helpful?​​​​​​​