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.
#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 Grid) within cells with the descriptions displayed as tooltips.