Skip to main content

Interface-Based Validation

  • 2 minutes to read

You can support error notifications for a custom data source (IList, ITypedList, IListSource, IBindingList, etc.).

When binding a grid to a custom data source (for example, data created at runtime), you create two classes:

  • The class that represents the data source. This class implements one of the interfaces (IList, IListSource, ITypedList, IBindingList), and provides access to the collection of records.
  • The class that implements a single record in a data source.

Objects that represent records in a data source should implement the IDXDataErrorInfo, IDataErrorInfo, or INotifyDataErrorInfo interface.

IDataErrorInfo

To display error notifications, the class that encapsulates a single record must implement the IDataErrorInfo interface. This interface includes two methods, that when implemented, get errors for the entire row and for individual cells (data source fields). As a result, the grid automatically displays error icons within cells with invalid values. When a user hovers a mouse over these icons, the grid displays a tooltip with an error description.

View Example: How to: Validate Data Rows and Indicate Errors

IDXDataErrorInfo

  • IDXDataErrorInfo.GetPropertyError - When implemented by a class, returns information on an error associated with the specified property (data field) of a data object.
  • IDXDataErrorInfo.GetError - When implemented by a class, returns information on an error associated with a data object (row).

INotifyDataErrorInfo

Starting from v18.1, the GridControl checks for and reports errors that are raised by a data source that implements INotifyDataErrorInfo.

When the INotifyDataErrorInfo.GetErrors method returns a collection with multiple values, the GridControl displays the first error from this collection. If this collection contains a custom object, an error tooltip contains a value that the ToString method returns.

To disable this validation type, set the DataViewBase.ValidatesOnNotifyDataErrors property to false.

Tip

If the GridControl is bound to DataView or DataTable, you can set errors for any cell within any row using methods provided by the data source. To set an error for the required cell, call the DataRow.SetColumnError method. The GridControl indicates these errors by displaying error icons (ErrorIcon_Critical) within cells with the descriptions displayed as tooltips.