[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Shapes, Pictures, Charts
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Expand]Examples
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[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)

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.

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

Display or hide circles around invalid data.

The SpreadsheetControl circles only first 255 invalid cells,

other invalid entries are ignored.

SpreadsheetControl.CircleInvalidData

SpreadsheetControl.ClearValidationCircles

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

Note

The maximum length of a list used to specify the DataValidationType.List validation type or a custom validation criteria is 255 characters. When a list or criteria exceeds this value, an InvalidOperationException is thrown.

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