[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [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]Property Grid
  [Expand]Pivot Grid
  [Collapse]Tree List
   [Expand]Product Information
   [Collapse]Feature Center
    [Expand]Data Binding
    [Expand]Data Editing
    [Expand]Data Presentation
      TreeList Sorting Specifics
      Sorting at Runtime
      Sorting via Code
      Custom Sorting
    [Expand]Appearances and Look And Feel
    [Expand]Focus, Selection and Navigation
     Formatting Cell Values
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End User Capabilities
   [Expand]Member Tables
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst 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]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Sorting via Code

Use the following approaches to sort data in code:

  • The TreeListColumn.SortOrder property sorts data recursively, starting from root nodes.

  • The TreeList.Sort and TreeListNode.Sort methods allow you to sort data recursively and non-recursively. For instance, you can only sort root nodes, without affecting the order of nested nodes.

Expanded Clear Sorting

To remove sorting against a column, set its TreeListColumn.SortOrder property to System.Windows.Forms.SortOrder.None, or call the Sort method with the System.Windows.Forms.SortOrder.None value as the order parameter.

To clear the sort settings for all columns, use the TreeList.ClearSorting method.

Expanded Avoid Superfluous Updates

Once you have changed the column's sort order, the Tree List rearranges and repaints nodes. If you sort by multiple columns, the Tree List rearranges nodes multiple times. You can avoid superfluous updates via the TreeList.BeginSort and TreeList.EndSort methods.

The following code sorts data against the Department and Budget columns. The TreeList.BeginSort and TreeList.EndSort methods wrap the code to avoid superfluous updates.

Expanded Sort Columns

The code above sorts data against the "Department" column, and then against the "Budget" column. To explicitly specify the order of sort columns, use the TreeListColumn.SortIndex property.

The TreeList.GetSortColumn and TreeList.SortedColumnCount members allow you to retrieve sort columns.

Expanded Sort Events

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

You can handle these events to perform custom actions.

Is this topic helpful?​​​​​​​