Skip to main content
A newer version of this page is available. .

TreeListCustomNodeSortEventArgs Class

Provides data for the ASPxTreeList.CustomNodeSort event.

Namespace: DevExpress.Web.ASPxTreeList

Assembly: DevExpress.Web.ASPxTreeList.v18.2.dll

Declaration

public class TreeListCustomNodeSortEventArgs :
    EventArgs

Remarks

The ASPxTreeList.CustomNodeSort event is raised when sorting is applied to a column, and allows a custom sorting algorithm to be implemented.

In an event handler two nodes should be compared. The result of the custom comparison indicates whether one node should be positioned above or below another node. To set the result of the custom comparison, use the TreeListCustomNodeSortEventArgs.Result property.

The nodes being processed are specified by the TreeListCustomNodeSortEventArgs.Node1 and TreeListCustomNodeSortEventArgs.Node2 properties. To retrieve node values, use the node’s TreeListNode.GetValue method. The processed column is returned by the TreeListCustomNodeSortEventArgs.Column property.

In most instances the TreeListCustomNodeSortEventArgs.Handled parameter should be set to true, to indicate that the comparison operation was handled and therefore no default processing is required. If the parameter is left set to false, the default comparison mechanism will be invoked after your event handler has been called, and this will override the custom result.

Example

The following code shows how to implement custom node sorting by handling the ASPxTreeList.CustomNodeSort event. The “DEPARTMENT” column displays text values. When sorting is applied to this column, the nodes are compared by the length of the “DEPARTMENT” column’s values rather than by the text itself.

The image below shows the result:

CustomNodeSort

using System.Collections;

protected void ASPxTreeList1_CustomNodeSort(object sender,
DevExpress.Web.ASPxTreeList.TreeListCustomNodeSortEventArgs e) {
    if (e.Column.FieldName != "DEPARTMENT") return;
    e.Handled = true;
    string value1 = e.Node1["DEPARTMENT"].ToString();
    string value2 = e.Node2["DEPARTMENT"].ToString();
    if (value1.Length > value2.Length)
        e.Result = 1;
    else
        if (value1.Length == value2.Length)
            e.Result = Comparer.Default.Compare(value1, value2);
        else
            e.Result = -1;
}

Inheritance

Object
EventArgs
TreeListCustomNodeSortEventArgs
See Also