Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Summaries
   [Collapse]Data Editing
    [Expand]Edit Form
    [Expand]Editing via Code
    [Expand]In-place Editors
    [Collapse]Input Validation
     [Expand]ErrorInfo Support
      Validating Editors
      Validating Rows
    [Expand]New Item Row
     Tutorial: Add or Remove Rows
     Tutorial: Data Input Validation
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [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]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Validating Rows

This topic describes how to check the validity of data entered by end-users into a row. Such validation is useful when the integrity of the row's data is important (when values in some fields depend on values in other fields). If you need to check the validity of data entered into individual cells, please refer to the Validating Editors topic.

Expanded Online Video

This video will first show you the built-in data validation mechanisms enabled in the Grid Control by default. You will then learn how to specify your own data cell validation rules and how to control the UI that informs end-users about the errors. Finally, you'll see how to enable row validation, which allows you to take into account values from multiple columns.

Expanded Validating Rows

There may be cases when you need to implement row validation. This is useful when your validation criteria involves several columns. For instance, you may want to ensure that one column value is greater than another. In this case, it is best to allow the end-user to move focus between cells and to perform validation when the row is about to lose focus. To do so, handle the ColumnView.ValidateRow event. Note that you can also initiate row validation manually by calling the ColumnView.UpdateCurrentRow method.

The event's RowHandle parameter identifies the row being validated. To obtain row values, you can, for instance, use the ColumnView.GetRowCellValue method, which requires the row handle and column to be used as parameters. After cell values have been obtained, you can verify whether the values meet your validity criteria or not. If the row fails validation, set the event's Valid parameter to false. Otherwise, leave the Valid parameter set to true.

By default, if the Valid parameter is set to false, the grid displays an error message box.

Clicking the Yes button returns focus to the row. This allows the end-user to correct row values. If the No button is clicked, the row's changes are discarded and focus can be moved away from the row. Note that the rollback only occurs if objects that represent records implement the System.ComponentModel.IEditableObject interface.

It is possible to provide an additional error description via the event's ErrorText parameter. The string assigned to this parameter will be displayed in the error message box followed by the "Do you want to correct the value?" string.

Sometimes you may want to indicate the cells containing invalid data to the end-user. For that purpose, call the ColumnView.SetColumnError method with the column and error description as parameters. As a result, the corresponding cell displays an error icon (). Pointing to the icon invokes the hint with the specified error description. This method allows you to set an error not only for specific cells but also for the entire row. For this purpose, call the ColumnView.SetColumnError method with null (Nothing in Visual Basic) as its column parameter. If an error is set for the row, the grid displays an error icon in the row indicator cell.

If the Valid parameter is set to false, the ColumnView.InvalidRowException event is raised after your ColumnView.ValidateRow event handler is completed. The ColumnView.InvalidRowException event allows you to override the default error presentation (displaying the error message box). It provides the ExceptionMode parameter that can be used to specify how to respond to the error.

ExceptionMode value Action
DisplayError Displays the error message box with an error description. The end-user can click an appropriate message box's button to choose between correcting values and discarding the changes.
Ignore Discards new data and reverts to an old value.
NoAction Suppresses displaying the error message box or throwing an exception. The value remains unchanged.
ThrowException Throws an exception.

The ColumnView.InvalidRowException event also occurs when the validated row cannot be saved to the bound data source due to database restrictions. In this case, an exception is usually raised by the data source. The object representing this exception can be obtained via the event's Exception parameter. You can use this parameter, for instance, to get the exception text and display it to the end-user.

When handling the ColumnView.ValidateRow or ColumnView.InvalidRowException event, it is possible to correct invalid cell values manually via the ColumnView.SetRowCellValue method. Refer to the Obtaining and Setting Cell Values section for more information on modifying rows.

Expanded Example

Assume that a Grid View contains two columns: "Units In Stock" and "Units On Order". A value in the first column must be more than the value of the second one. So we need to perform validation of a row when it is about to be saved to the data source. For this purpose, the ColumnView.ValidateRow event is handled.

If row fails validation, we set errors for the columns with coresponding descriptions using the ColumnView.SetColumnError method. The descriptions will be displayed when hovering over error icons.

The ColumnView.InvalidRowException event is handled in order to suppress displaying the default error message box.

The following screenshot shows a Grid View after a row fails validation.

Expanded See Also

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