Skip to main content

TreeList.InvalidNodeException Event

Fires when a node fails validation or when its data cannot be saved to the data source.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

[DXCategory("Action")]
public event InvalidNodeExceptionEventHandler InvalidNodeException

Event Data

The InvalidNodeException event's data class is InvalidNodeExceptionEventArgs. The following properties provide information specific to this event:

Property Description
ErrorText Gets or sets the error description to be displayed in the message box/tooltip. Inherited from ExceptionEventArgs.
Exception Gets the exception that caused the event. Inherited from ExceptionEventArgs.
ExceptionMode Gets or sets the type of response to supplying invalid values. Inherited from ExceptionEventArgs.
Node Gets the node that failed validation.
WindowCaption Gets or sets the caption of the error message box. Inherited from ExceptionEventArgs.

Remarks

If a node was modified and is about to lose focus, the TreeList.ValidateNode event is raised. You can handle this event to specify if the node’s data is valid. If the node fails validation or its data cannot be saved to the data source due to database restrictions, the InvalidNodeException is raised. Note that you can avoid invalid values at the validation stage by leaving the node focused so that end-users can correct the values entered. Another alternative is to discard the changes made.

Handle the InvalidNodeException event to provide an appropriate response to the entry of invalid data. The node whose data failed validation, can be identified using the InvalidNodeExceptionEventArgs.Node parameter. The exception that raised the event and the error description can be obtained via the ExceptionEventArgs.Exception and ExceptionEventArgs.ErrorText parameters respectively. The actual response is specified by the ExceptionEventArgs.ExceptionMode parameter. You can display an error message box, discard changes made, raise an exception or take no action.

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