Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Collapse]Spreadsheet
    Product Structure
   [Expand]Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
    Themes and Templates
   [Expand]Examples
  [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]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

Data Validation

This document introduces the Data Validation concept and demonstrates how to manage data validation rules in a worksheet using the Data Validation API.

Expanded Data Validation Overview

Data validation allows restricting the data which can be entered in a cell. It assists the users in entering data that is valid. You can allow entering invalid data, but warn the users when that occurs. You can also provide messages to explain the reason for the restriction or to instruct users how to correct errors.

End-users are provided with the Data Tools command group located on the Data Ribbon tab, to invoke a Data Validation dialog and to identify cells with invalid data by displaying a red circle around them.

Note

Note that the Circle Invalid Data command circles only first 255 invalid cells, other invalid entries are ignored.

When a user attempts to enter a value that is not correct according to validation rules, an alert is shown. Alert text is specified with the XtraSpreadsheetStringId.Msg_DataValidationFailed enumeration member so it can be easily localized, as described in the Localization topic.

You can also provide a custom message that explains what data can be entered in a cell, and a custom error dialog that appears when incorrect data is entered.

Expanded Data Validation API

The DataValidation interface provides information describing the data validation rule - the DataValidation.Range in which the rule is in effect, the DataValidation.ValidationType and other options which can be used while validating data.

Data validation rules in a worksheet are contained in the DataValidationCollection collection which is accessible via the Worksheet.DataValidations property.

To add a new data validation rule, use the DataValidationCollection.Add method of the collection. To cancel a particular rule, remove it from the collection. To remove all data validation rules, clear the collection.

Expanded Data Validation Common Tasks

Task

API Members

User Interface

Restrict data to predefined items in a list. DataValidationType.List
Restrict numbers outside a specified range. DataValidationType.WholeNumber
DataValidationType.Decimal
DataValidationOperator.Between
Restrict dates and times outside a certain time frame. DataValidationType.Time
DataValidationOperator.LessThanOrEqual
Limit the number of text characters. DataValidationType.TextLength
DataValidationOperator.Equal
Validate data based on formulas or values in other cells. DataValidationType.Custom
Create a message that explains what data can be entered in a cell. DataValidation.InputTitle
DataValidation.InputMessage
DataValidation.ShowInputMessage
Create a message that appears when the end-user types incorrect data. DataValidation.ErrorTitle
DataValidation.ErrorMessage
DataValidation.ErrorStyle
DataValidation.ShowErrorMessage

The code snippet below illustrates how to create and apply different validation criteria to worksheet cells using Data Validation API.

Show Me

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

How would you rate this topic?​​​​​​​