Sorting in Windows Forms MultiColumn TreeView
8 Jul 20262 minutes to read
Nodes can be sorted by the check box, tag, or text values, in ascending or descending order.
The sort operation sorts only the level 1 nodes. To sort the other levels of nodes, the SortWithChildNode property should be set to true. The sort function can be performed using the Sort method on a TreeNodeAdv collection, where the sort order is defined as an argument of the method.
Method Table
| TreeNodeAdv Collection Method | Description |
|---|---|
| Sort (SortOrder order) | The SortOrder property indicates the order of the sorting: Ascending, Descending, None. |
// Sort method with Descending order as argument
this.MultiColumnTreeView1.Nodes.Sort(SortOrder.Descending);Me.MultiColumnTreeView1.Nodes.Sort(SortOrder.Descending)The sort can be performed on a specific value type, specified using SortType (Checkbox, Tag, or Text). The order of the sort is specified using SortOrder, which holds the values of Ascending or Descending.
| TreeNodeAdv Property | Description |
|---|---|
| SortOrder | The SortOrder property indicates the order of the sorting: Ascending, Descending, None. |
| SortType | The SortType property indicates the field. Nodes will be sorted based on the type of sorting. |
this.MultiColumnTreeView1.Nodes[0].SortType = Syncfusion.Windows.Forms.Tools.MultiColumnTreeView.TreeNodeAdvSortType.CheckBox;
this.MultiColumnTreeView1.Nodes[0].SortOrder = SortOrder.Descending;Me.MultiColumnTreeView1.Nodes(0).SortType = Syncfusion.Windows.Forms.Tools.MultiColumnTreeView.TreeNodeAdvSortType.CheckBox
Me.MultiColumnTreeView1.Nodes(0).SortOrder = SortOrder.Descending- Sort in Ascending

- Sort in Descending

Comparing Options for Sorting
The CompareOptions property specifies additional options for comparing node text during sorting.
The Comparer property is an object that implements the IComparer interface. If you need to compare the nodes by some other field, create an object of this type, set it to the node and that node will use the object to compare its child nodes.
Property Table
| TreeNodeAdv Property | Description |
|---|---|
| CompareOptions |
Indicates the compare options used in the sorting of the nodes.
|
| Comparer | Indicates the object which compares two nodes. |
node.CompareOptions = System.Globalization.CompareOptions.IgnoreCase;
node.Comparer = null;node.CompareOptions = System.Globalization.CompareOptions.IgnoreCase
node.Comparer = Nothing