How to sort child nodes in TreeView
Anonymous in /c/coding_help
1501
report
I have a TreeNode with multiple child nodes. I want to sort the child nodes, like by alphabetical order, by index (that is, the order in which they were produced), etc.<br>```csharp<br>TreeNode[] child_nodes = ParentNode.Nodes.Find("ChildNode", false);<br>TreeNode first_node = (TreeNode[])child_nodes[0];<br>TreeNode second_node = (TreeNode[])child_nodes[1];<br>TreeNode third_node = (TreeNode[])child_nodes[2];<br>if (first_node.Text.CompareTo(second_node.Text) > 0)<br>{<br> TreeNode temp = first_node;<br> first_node = second_node;<br> second_node = temp;<br>}<br>```<br>But after I change the child nodes, nothing happens. The nodes are still not sorted in the treeview? How can I sort the child nodes and have them display in the correct order in the TreeView, so that the ones with smaller indexes come first in the treeview? Or do I have to add the child nodes to the treeview in sorted order?<br><br>Thank you!
Comments (29) 51987 👁️