How to sort WinForms MultiColumnTreeView based on the ColumnIndex?
Sorting
In WinForms MultiColumnTreeView, Nodes can be sorted in ascending or descending order by using its function named Sort.
C#
//Pass the column index and root of the MultiColumnTreeView SortNodesByColumn(this.multiColumnTreeView1.Root, 1); //To Sort the MultiColumnTreeView based on the Column index private void SortNodesByColumn(TreeNodeAdv ParentNode, int ColumnIndex) { foreach (TreeNodeAdv node in ParentNode.Nodes) { if (node.HasNodes) { SortNodesByColumn(node, 1); } node.Nodes.Sort(new SortBySubItems(this.multiColumnTreeView1, ColumnIndex,this.CheckBox1.Checked)); } }
VB
'Pass the column index and root of the MultiColumnTreeView Me.multiColumnTreeView1.Nodes.AddRange(New TreeNodeAdv(){root1,root2,root3,root4}) 'To Sort the MultiColumnTreeView based on the Column index Private Sub SortNodesByColumn(ByVal ParentNode As TreeNodeAdv, ByVal ColumnIndex As Integer) For Each node As TreeNodeAdv In ParentNode.Nodes If node.HasNodes Then SortNodesByColumn(node, 1) End If node.Nodes.Sort(New SortBySubItems(Me.multiColumnTreeView1, ColumnIndex, Me.CheckBox1.Checked)) Next node End Sub
Figure 1. MultiColumnTreeView sorted using Column Index and root node
Samples:
C#: SortMultiColumnTreeView C#
VB: SortMultiColumnTreeView VB
Conclusion
I hope you enjoyed learning about how to sort WinForms MultiColumnTreeView based on the ColumnIndex.
You can refer to our WinForms MultiColumnTreeView’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms MultiColumnTreeView documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms MultiColumnTreeView and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!