Version

DataErrorInfo Support

Topic Overview

Purpose

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.

Required background

The following topic is a prerequisite to understanding this topic:

Topic Purpose

This topic will provide background information about IDataErrorInfo (.NET) interface used for row and cell errors to data bound controls.

Configuring DataErrorInfo in Cell and Row

Introduction

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.

Note
Note:

While it is possible to override the DataSource’s error text using the DataErrorInfo applied to UltraGridRow , you cannot replace the errors presented on the DataSource with an empty string in an effort to hide or remove the text. Attempting to do so will display the error text from DataSource.

Enabling DataErrorInfo

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

Applying data error to a cell

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")
WinGrid DataErrorInfo Support 1.png

Applying data error to a row

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
WinGrid DataErrorInfo Support 2.png

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.

Related Content

Topics

The following topic provides additional information related to this topic.

Topic Purpose

In this list of sections you may find short, task-based topics that explain how to perform specific tasks related to the WinGrid control.