Skip to main content
All docs
V24.2

TreeViewControl.CustomNodeSort Event

Allows you to use custom rules to sort data.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.2.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event TreeViewCustomNodeSortEventHandler CustomNodeSort

Event Data

The CustomNodeSort event's data class is DevExpress.Xpf.Grid.TreeList.TreeViewCustomNodeSortEventArgs.

Remarks

Follow the steps below to apply custom logic to sort data:

  1. Set the SortOrder property to Ascending or Descending.
  2. Set the SortMode property to Custom.
  3. Handle the CustomNodeSort event.

When you handle this event, you need to compare two nodes. The Value1 and Value2 parameters identify the values of these nodes. Set the result of the comparison to the Result parameter as follows:

  • -1 to position the first row above the second row when data is sorted in ascending order. When data is sorted in descending order, the TreeViewControl positions the first row below the second row.
  • 1 to position the first row below the second row when data is sorted in ascending order. When data is sorted in descending order, the TreeViewControl positions the first row above the second row.
  • 0 to indicate that the rows are equal. In this case, the TreeViewControl arranges rows according to their indices in a data source.

Set the Handled parameter to true to use the custom comparison. Leave this parameter set to false to invoke the default comparison mechanism after your event handler has finished. In this instance, the TreeViewControl ignores the custom comparison’s result.

Example

<dxg:TreeViewControl SortOrder="Ascending"
                     SortMode="Custom" 
                     CustomNodeSort="treeview_CustomNodeSort"
                     ...>
void treeview_CustomNodeSort(object sender, DevExpress.Xpf.Grid.TreeList.TreeViewCustomNodeSortEventArgs e) {
    int dayIndex1 = GetDayIndex((string)e.Value1);
    int dayIndex2 = GetDayIndex((string)e.Value2);
    e.Result = dayIndex1.CompareTo(dayIndex2);
    e.Handled = true;
}
int GetDayIndex(string day) {
    return (int)Enum.Parse(typeof(DayOfWeek), day);
}
See Also