Skip to main content

TreeList.SetColumnError(TreeListColumn, String) Method

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

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.2.dll

Declaration

public virtual void SetColumnError(
    TreeListColumn column,
    string errorText
)

Parameters

Name Type Description
column TreeListColumn

A TreeListColumn 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 node.

errorText String

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

Remarks

Use this method to assign errors to nodes or individual cells. This can be useful, if you perform input validation by handling the TreeList.ValidatingEditor or TreeList.ValidateNode 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 node, the icon is displayed within the node indicator. Pointing to error icons with the mouse displays a hint with the appropriate error description.

The image below shows an error cell example:

ColumnView.SetColumnError

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

In order to provide error support for IList data sources, you need to implement the IDataErrorInfo interface.

Example

Assume that there are two columns in a Tree List: “OrderDate” and “RequiredDate”. The value in the first column must be less than the value in the second one. So we need to validate a node when it is about to be saved to the data source. For this purpose, the TreeList.ValidateNode event is handled.

If a node fails validation, we set errors for the columns with corresponding descriptions using the TreeList.SetColumnError method. The descriptions will be displayed when hovering over the error icons.

The TreeList.InvalidNodeException event is handled in order to suppress displaying the default error message box.

The following screenshot shows the Tree List after a node fails validation.

TreeList_ValidateRow

Note that the TreeListOptionsBehavior.ShowToolTips option must be enabled to allow tooltips to be displayed.

using DevExpress.XtraTreeList;

private void treeList1_ValidateNode(object sender, ValidateNodeEventArgs e) {
    DateTime time1 = (DateTime)e.Node[colOrderDate];
    DateTime time2 = (DateTime)e.Node[colRequiredDate];
    if(time1 >= time2) {
        e.Valid = false;
        //Set errors with specific descriptions for the columns
        treeList1.SetColumnError(colOrderDate, "The value must be less than RequiredDate");
        treeList1.SetColumnError(colRequiredDate, "The value must be greater than OrderDate");
    }

}

private void treeList1_InvalidNodeException(object sender, InvalidNodeExceptionEventArgs e) {
    //Suppress displaying the error message box
    e.ExceptionMode = ExceptionMode.NoAction;
}
See Also