Version

Data Validation Overview

Topic Overview

Purpose

This topic explains how to work with the validation feature.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the xamDataGrid control including a conceptual diagram of its comprising elements.

In this topic

This topic contains the following sections:

Overview

Summary

If your data items implement the INotifyDataErrorInfo or IDataErrorInfo interface found in the .NET Framework, the DataPresenter family of controls can display an error message(s) when the user enters invalid data in a cell. However, you must enable the data error information support by setting a FieldLayoutSettings object’s SupportDataErrorInfo property to a SupportDataErrorInfo enumeration value.

In addition to enabling support for data errors, the SupportDataErrorInfo property determines whether the DataPresenter control displays the data error in a cell, record selector, or both.

The following screenshot shows a data error in the first record’s "ProductID" column:

xamDataPresenter About Data Validation 01.png
Note
Note

The INotifyDataErrorInfo interface takes precedence over the IDataErrorInfo interface when both interfaces are implemented by the data items. The advantage of using the INotifyDataErrorInfo interface is that you may have more than one error message per record and/or cell.

Configure data error support

The following table shows how the DataPresenter control accesses the methods/properties of the data items in order to obtain the error information which ultimately depends on the value of the SupportDataErrorInfo property.

Value set on the SupportDataErrorInfo property Interface used by the data item

IDataErrorInfo

INotifyDataErrorInfo

RecordsOnly

Obtain record’s error message by querying the Error property.

Obtain record’s error messages by querying the GetErrors() method with an empty string as an argument value.

CellsOnly

Obtain each property error message by querying the data item’s indexer and passing the property name as an argument.

Obtain each property error messages by querying the GetErrors() method with the property name as an argument value.

RecordsAndCells

Both of the above.

Both of the above.

If you enable the data error support on the FieldLayoutSettings object, any fields in the affected field layout will automatically report data errors. You can selectively disable this feature on a field by setting the SupportDataErrorInfo property exposed by a field object’s FieldSettings property to false.

You can also modify how the DataPresenter control reports data errors by setting a FieldLayoutSettings object’s DataErrorDisplayMode property to a DataErrorDisplayMode enumeration value. Setting the DataErrorDisplayMode property determines whether a data error is presented as an error icon, a highlight, or both.

Editor’s Value Constraints

If you enable support for either the IDataErrorInfo interface or the INotifyDataErrorInfo interface and you set the ValueConstraint property of an embedded xamEditor control, any value constraint errors will also cause the error icon and/or highlight to appear. Value constraints will force your end users to correct an error before they can move focus to a new cell. If you set a FieldSettings object’s InvalidValueBehavior property to RevertValue, the cell’s value will automatically revert to its original value allowing your end users to move focus to a new cell. However, because the valued will always pass the value constraints, the DataPresenter control will never display an error icon and/or highlight. On the other hand, if you do not use value constraints, the DataPresenter control will display your data item’s error message in the appropriate cell and your end users can move focus to a new cell.

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how to enable the data error support with code examples.

This topic explains how to provide validation feedback as the user edits a cell value.

This topic explains how to provide custom styling for the visual data validation indication.

This topic explains how to define custom validation logic.