ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsAndCells;
Not to be confused with the existing IDataErrorInfo interface, this topic introduces the WinGrid™ control’s extended data validation feature and provides configuration examples to further your understanding.
The following topic is a prerequisite to understanding this topic:
This topic contains the following sections:
The WinGrid control already supports displaying errors, images and tooltips in rows and cells where the grid’s data source returns information via the IDataErrorInfo
interface. Since the data errors were set and retrieved from the data source, the data validation was unavailable in unbound columns cells.
The UltraGridRow.UltraGridRowDataErrorInfo property allows getting or setting error information in rows, and cells within a row. This information is completely independent of any error information returned by the data source’s implementation of IDataErrorInfo. Applying an error to the UltraGridRow.DataErrorInfo
does not affect the underlying data source errors in any way.
You can display data errors in cells of unbound columns, and rows that have not used the IDataErrorInfo
interface. It also allows you to override the retrieved error text from the data source directly in UltraGridRow object.
To support the feature, you must first enable the SupportDataErrorInfo before applying or retrieving any errors on the grid.
Possible SupportDataErrorInfo
enumeration options are:
CellsOnly
Default (No support)
None
RowsAndCells
RowsOnly
In C#:
ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsAndCells;
In Visual Basic:
ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsAndCells
Use the SetColumnError method to set cells with data error information in the InitializeRow event.
In C#:
if ((double)e.Row.Cells["BasePrice"].Value == 0)
e.Row.DataErrorInfo.SetColumnError("BasePrice", "Cell Error: Zero is invalid.");
In Visual Basic:
If CDbl(e.Row.Cells("BasePrice").Value) = 0 Then
e.Row.DataErrorInfo.SetColumnError("BasePrice", "Cell Error: Zero is invalid.")
End If
Use the GetColumnError method to retrieve a cell’s data error information.
In C#:
string columnError = e.Row.DataErrorInfo.GetColumnError("BasePrice");
In Visual Basic:
Dim columnError As String = e.Row.DataErrorInfo.GetColumnError("BasePrice")
The following code example uses the RowError property to apply data error information to a row in the InitializeRow event.
In C#:
if ((double)e.Row.Cells["BasePrice"].Value == 0)
e.Row.DataErrorInfo.RowError = "Row contains invalid cell values...";
In Visual Basic:
If CDbl(e.Row.Cells("BasePrice").Value) = 0 Then
e.Row.DataErrorInfo.RowError = "Row contains invalid cell values..."
End If
As a side note, you can retrieve the resolved errors using DataErrorInfoResolved property, which returns the resolved error information from the data source and grid rows.
The following topic provides additional information related to this topic.