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

Sorting via Code

Expanded Sorting via Code

Use a column's TreeListColumn.SortOrder property, to apply sorting to it. To sort the values of the column in ascending order, set the TreeListColumn.SortOrder property to the System.Windows.Forms.SortOrder.Ascending value. To sort in descending order, set it to the System.Windows.Forms.SortOrder.Descending value.

To remove sorting against a column set its TreeListColumn.SortOrder property to the System.Windows.Forms.SortOrder.None value. If the sort settings for all the columns needs to be removed, call the Tree List's TreeList.ClearSorting method.

The following code shows how to sort data against the Department column in ascending order:

Once the column's sort order has been changed, the Tree List's nodes are rearranged and repainted. If sorting by several columns, the nodes will be rearranged as many times as there are columns involved in the sorting. This can be avoided by using the TreeList.BeginSort and TreeList.EndSort methods. The first method prevents the Tree List control from rearranging its nodes as a result of sorting until the second method is called. This allows sorting to be applied against several columns, and the nodes to be rearranged only once, as a result.

The number of sorted columns is returned by the TreeList.SortedColumnCount property. The column's TreeListColumn.SortIndex property allows the position of the column in the list of sorted columns to be determined. The columns involved in sorting can be accessed using the TreeList.GetSortColumn method.

When the sort settings for a column are changed, the Tree List does the following:

Expanded Example

The following sample code demonstrates how to apply sorting to the Department and Budget columns. Data is sorted via the TreeListColumn.SortOrder property. To avoid superfluous updates, the code is enclosed with the TreeList.BeginSort and TreeList.EndSort methods.

Expanded Example

The following sample code uses the TreeList.GetSortColumn method and the TreeList.SortedColumnCount property to traverse through columns involved in sorting.

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