[Expand]General Information
[Collapse]WinForms Controls
 [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 With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Collapse]Data Editing and Validation
    [Collapse]ErrorInfo Support
      Internal ErrorInfo Support
      Implementing ErrorInfo Support for Data Sources
     Add and Remove Rows
     Modify and Validate Cell Values
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
   [Expand]Hit Information
    Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [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]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)

Internal ErrorInfo Support

Grid Control provides methods with which you can get and set errors for any cell within a focused record and for the entire focused record. For instance, you may verify the focused record, and if invalid data is encountered, set errors for particular cells. The grid control will indicate the cells and the record, for which errors are set, by displaying error icons. This section describes the methods provided by Grid Control for that purpose.

Setting errors for the focused record/record cells can be useful, for instance, when validating the user's input. Grid Control allows you to validate data the end-user enters via the BaseView.ValidatingEditor and ColumnView.ValidateRow events. When handling these events, you can set errors for specific cells or for the entire record to indicate invalid data. For more information on validating, see the Modify and Validate Cell Values and Modify and Validate Cell Values sections.

Expanded Internal ErrorInfo Support

To indicate that particular cells of the focused record contain invalid data, you can call the ColumnView.SetColumnError method. This allows you to set an error description for a specific column or for the entire record. It is also possible to specify the type of error using the ColumnView.SetColumnError method overload, which takes an ErrorType parameter. The error type identifies the error icon to be displayed within the cell. The following predefined error icons are available: , and . In addition, you can provide custom error icons.

If an error description is set for a column, an error icon is displayed within a corresponding cell. If you set an error description for a record, the error icon is displayed in the row indicator's cell (for Grid Views) and within the card caption (for Card Views). The following images illustrate errors that are set for cells and records for a Grid View and Card View respectively.

GridView CardView

If you need to provide a more complex error presentation, you can use the custom draw and Appearance techniques. For instance, you may want to indicate the error by displaying custom information within the column header which contains an invalid value. For this purpose, you can handle the GridView.CustomDrawColumnHeader event.

To get and clear column and record errors, use the following methods: All error related methods provided by Grid Control work with the focused row. However, if the view is bound to a System.Data.DataTable or System.Data.DataView data source, it is possible to set and get errors for cells in any row using methods of the corresponding System.Data.DataRow object (System.Data.DataRow.SetColumnError and System.Data.DataRow.GetColumnError). The grid will indicate cells containing invalid data with error icons. The error related methods provided by Grid Control do not allow you to work with error descriptions which are set via the data source.

To implement error support for other data sources, you need to implement the System.ComponentModel.IDataErrorInfo or IDXDataErrorInfo interface. See the Implementing ErrorInfo Support for Data Sources section for an example.

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

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