ColumnView.SetColumnError(GridColumn, String) Method

Sets an error description for a cell within the focused row or for the entire focused row.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public virtual void SetColumnError(
    GridColumn column,
    string errorText
)
Public Overridable Sub SetColumnError(
    column As GridColumn,
    errorText As String
)

Parameters

Name Type Description
column GridColumn

A GridColumn object representing a column that contains an error cell. null (Nothing in Visual Basic) if the error description should be assigned to the entire focused row.

errorText String

A string value representing an error description. An empty string to clear the assigned error.

Remarks

Use the method to assign errors to rows or individual cells. This can be useful, if you perform input validation by handling the ColumnView.ValidateRow event and wish to indicate input errors within cells.

Setting an error description for a cell results in displaying an error icon for the cell. If an error description is set for the entire row, the icon is displayed within the row indicator cell. Pointing to error icons with the mouse displays a hint window with the appropriate error description.

The image below shows an error cell example:

ColumnView.SetColumnError

If a View's data source is a DataView or a DataTable, you can set errors for individual rows using the SetColumnError method of data rows. The View will also mark such rows with the error icon. Note, however, that methods provided by the ColumnView class do not allow you to work with such errors. Instead, use members provided by the DataRow object to handle errors assigned in that way.

In order to provide error support for IList data sources, you need to implement the IDataErrorInfo or IDXDataErrorInfo interface. Refer to the Implementing ErrorInfo Support for Data Sources document for details.

The SetColumnError method does not set errors for fields displayed in the edit form when the GridOptionsEditForm.BindingMode option is set to Cached.

NOTE

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the SetColumnError member must not be invoked for these Views. The SetColumnError member can only be used with real Views that are displayed within the Grid Control. The real Views with which an end-user interacts at runtime can be accessed using the following methods.

Examples

The example below tracks changes made to the "Units In Stock" and "Units On Order" columns. If an edited record has its "In Stock" value less than "On Order", this row is considered invalid. In this case the e.Valid parameter of the ColumnView.ValidateRow event is set to false.

The default warning message does not pop up since the ExceptionMode parameter of the ColumnView.InvalidRowException event is set to NoAction. Instead, the ColumnView.SetColumnError method displays error icons in both cells.

ColumnView_ValidateRow

using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraEditors.Controls;

private void gridView1_ValidateRow(object sender, 
DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) {
    GridView view = sender as GridView;
    GridColumn inStockCol = view.Columns["UnitsInStock"];
    GridColumn onOrderCol = view.Columns["UnitsOnOrder"];
    //Get the value of the first column
    Int16 inSt = (Int16)view.GetRowCellValue(e.RowHandle, inStockCol);
    //Get the value of the second column
    Int16 onOrd = (Int16)view.GetRowCellValue(e.RowHandle, onOrderCol);
    //Validity criterion
    if (inSt < onOrd) {
        e.Valid = false;
        //Set errors with specific descriptions for the columns
        view.SetColumnError(inStockCol, "The value must be greater than Units On Order");
        view.SetColumnError(onOrderCol, "The value must be less than Units In Stock");
    }
}

private void gridView1_InvalidRowException(object sender, 
DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs e) {
    //Suppress displaying the error message box
    e.ExceptionMode = ExceptionMode.NoAction;
}
See Also