Sorting in Windows Forms MultiColumn TreeView

Sorting can be performed on the tree nodes using the Sort function and specifying the function to be performed on either the checkbox or tag or text values in ascending or descending order.

The Sort operation sorts only the level 1 nodes. To perform the function on the other levels of nodes, the SortWithChildNode property should be set to true. The sort function can be performed using the Sort method in Tree node where sort order can be defined as an argument in 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

The sort function can be done based on the value type which can be specified using SortType to either the option of Checkbox or Tag or Text. The order in which the sort function has to be performed can be specified using the SortOrder that 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 gives additional options of comparing the texts of the nodes.
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 in comparing the sub nodes.

Property Table

TreeNodeAdv Property Description
CompareOptions Indicates the compare options used in the sorting of the nodes.
  • IgnoreCase
  • IgnoreKanaType
  • IgnoreNonSpace
  • IgnoreSymbols
  • IgnoreType
  • IgnoreWidth
  • None
  • Ordinal
  • OrdinalIgnoreCase
  • StringSort
  • 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