[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
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [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
      Interfaces-Based Validation
      Attributes-Based Validation
    [Expand]Clipboard Management
   [Expand]Filtering and Searching
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus, Navigation, Selection
   [Expand]Conditional Formatting
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [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
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Row Validation

The GridControl allows you to validate new row values.

Use the row validation if the row's data is interrelated (for example, values in some columns depend on other column values). See the Cell Validation topic to learn how to validate cell values.

The image below shows a GridControl with an invalid row:


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

Follow the steps below to validate a row:

Expanded Step 1. Handle a Validating Event

The GridControl provides the GridViewBase.ValidateRow and TreeListView.ValidateNode events to validate row values manually. These events are raised after a focused row's data changes.

The code sample below shows how to validate rows:

You can call the DataViewBase.CommitEditing method to manually force the row validation.

Expanded Step 2. Validate a New Value

Use the following GridRowValidationEventArgs's properties to get row values:

You can verify row values according to validation rules after obtaining them. If a row fails validation, set the ValidationEventArgs.IsValid property to false.

In the following code sample, the StartDate value cannot be greater than EndDate value:

Expanded Step 3. Indicate Errors

The GridControl shows the following hints to indicate if a row contains invalid data:

An Error Tooltip

The GridControl shows an error tooltip when the mouse pointer hovers over an invalid row. Specify the ValidationEventArgs.ErrorContent property to set the error tooltip's description:

The image below shows the result:

An Error Window

The GridControl displays an error window after an end user enters an incorrect value. This window allows them to perform the following actions:

  • Click Yes to return focus to the edited row and correct the row value.
  • Click No to discard the changes. In this case, an end-user can move the focus away from the row. The rollback only occurs if objects that represent rows implement the System.ComponentModel.IEditableObject interface.

Handle the GridViewBase.InvalidRowException event, which is raised after the GridViewBase.ValidateRow event, and use the following InvalidRowExceptionEventArgs's properties to override the default error presentation:

The code sample below demonstrates how to disable the error window and display the error tooltip only:

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