Back to Devexpress

TreeListCustomNodeSortEventArgs Class

aspnet-devexpress-dot-web-dot-aspxtreelist-96ab991f.md

latest4.8 KB
Original Source

TreeListCustomNodeSortEventArgs Class

Provides data for the ASPxTreeList.CustomNodeSort event.

Namespace : DevExpress.Web.ASPxTreeList

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

NuGet Package : DevExpress.Web

Declaration

csharp
public class TreeListCustomNodeSortEventArgs :
    EventArgs
vb
Public Class TreeListCustomNodeSortEventArgs
    Inherits EventArgs

TreeListCustomNodeSortEventArgs is the data class for the following events:

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:

csharp
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;
}
vb
Imports System.Collections

Protected Sub ASPxTreeList1_CustomNodeSort(ByVal sender As Object,_
ByVal e As DevExpress.Web.ASPxTreeList.TreeListCustomNodeSortEventArgs)
        If e.Column.FieldName <> "DEPARTMENT" Then
            Return
        End If
        e.Handled = True
        Dim value1 As String = e.Node1("DEPARTMENT").ToString()
        Dim value2 As String = e.Node2("DEPARTMENT").ToString()
        If value1.Length > value2.Length Then
            e.Result = 1
        Else
            If value1.Length = value2.Length Then
                e.Result = Comparer.Default.Compare(value1, value2)
            Else
                e.Result = -1
            End If
        End If
End Sub

Inheritance

Object EventArgs TreeListCustomNodeSortEventArgs

See Also

TreeListCustomNodeSortEventArgs Members

Tree List

DevExpress.Web.ASPxTreeList Namespace