Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]Welcome to DevExpress .NET Documentation
[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
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
   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
     Data Editing Overview
     Edit Form
     New Item Row
    [Expand]Inplace Editors
    [Collapse]Input Validation
      Cell Validation
      Row Validation
      Validating Nodes and Node Cells
      Error Notification
      Attributes-Based Validation
      Examples
    [Expand]Editing in Code
    [Expand]Clipboard Management
     Moving Nodes in TreeList
   [Expand]Grouping
   [Expand]Selection
   [Expand]Filtering and Searching
   [Expand]Sorting
   [Expand]Data Summaries
   [Expand]Data 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]Diagram Control
  [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]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Attributes-Based Validation

DXGrid for WPF 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.

Expanded Example: How to Implement Attributes-Based Validation

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3191.

This example shows how to apply DataAnnotations attributes that specify data validation rules. The RequiredAttribute is applied to the 'Name' and 'Department' data fields. The StringLengthAttribute is applied to the 'Position' data field.

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