Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Collapse]Tree List
   [Expand]Product Information
   [Collapse]Feature Center
    [Expand]Data Binding
    [Expand]Nodes
    [Expand]Data Editing
    [Expand]Data Representation
    [Collapse]Sorting
      TreeList Sorting Specifics
      Sorting at Runtime
      Sorting via Code
      Custom Sorting
    [Expand]Filtering
    [Expand]Summaries
    [Expand]Appearances and Look And Feel
    [Expand]Focus, Selection and Navigation
     Formatting Cell Values
    [Expand]Miscellaneous
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End User Capabilities
   [Expand]Member Tables
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Custom Sorting

Expanded Custom Sorting

The Tree List control allows custom sorting algorithms to be implemented for individual columns. These sorting procedures are invoked when data is sorted against specific columns by end-users, or via the TreeListColumn.SortOrder property.

To enable the use of a custom sorting procedure for a column, set the column's TreeListColumn.SortMode property to Custom. To implement custom sorting logic, handle the TreeList.CustomColumnSort event. When sorting is applied to this column, this event fires each time two node values in the column must be compared.

The result of the node value comparison is specified by the sign of the event's Result parameter. If it is negative, the first compared value is considered to be the smaller value. If it is positive, the first compared value is considered to be the larger value. Setting Result to 0 specifies that the nodes have identical values. Initially, this parameter contains a value specified by the default sorting algorithm.

Expanded Example

The code below implements a custom sorting algorithm for a Tree List column via the TreeList.CustomColumnSort event. The sorting procedure arranges nodes that have children above the nodes that do not have children.

The images below display the control sorted by the Department column in ascending and descending order. Notice that the Finance node is always located under nodes that have children.

Expanded Example

Custom sorting can be used if you wish to sort string values as numbers. Assume that the values "2" and "10" exist within a column. If standard sorting is used, "10" will be considered to be less than "2", so write the following TreeList.CustomColumnSort event handler to avoid this behavior.

Sorting string values as numbers is not the only reason to implement custom sorting. You can also use this feature if you want sorting to be dependent upon the properties of nodes, or upon the data in other columns.

How would you rate this topic?​​​​​​​