Row Validation

This topic describes how to check validity of data entered by end-users into a data row. This is useful when the integrity of row data is important (for instance, when values in some columns depend on values in others).

Row validation is performed in the GridControl.ValidateRow event handler when a row is about to lose focus. To manually force row validation, call the DataControlBase.CommitEditing method.

The processed row is returned by the event parameter's Row property. Its handle is returned by the RowHandle property. After cell values have been obtained, you can verify whether the values meet your validity criteria. If the row fails validation, set the event's IsValid parameter to false. Otherwise, keep the IsValid parameter set to true.

By default, if the row contains invalid data, the error message box is displayed. Clicking the Yes button returns focus to the row. This allows an end-user to correct row values. If the No button is clicked, the row's changes are discarded and focus can be moved from the row. Note that the rollback occurs only if objects that represent rows implement the System.ComponentModel.IEditableObject interface.

Grid Validation Error

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. To change the error window's default caption, use the WindowCaption property.

To override the default error presentation, handle the GridControlBase.InvalidRowException event that occurs after the GridControl.ValidateRow event. Use the event parameter's InvalidRowExceptionEventArgs.ExceptionMode property to specify the action performed in response to entering an invalid value. You can display a message box with an error description, suppress any action, throw an exception or discard new data, and revert to an old value.