Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i sort child node in Treeview

Status
Not open for further replies.

dotnetguy

Programmer
Apr 13, 2005
7
US
Hi All,

I've an treeview and I want to sort selected node's child nodes,

Node1
Node11
Node12
Node13
Node2
Node21
Node22
Node23
Node3
Node31


I want to sort Node1 only not entire treeview

Thanks
Aa

 
As you probably know, the Sorted property of a TreeView applies to all nodes, not just a selected node.

There are two ways I can think (without any testing) of sorting a specific nodes children:

1. Sort them before they are added, if possible

2. Add all the child nodes to an ArrayList and sort the ArrayList. You may need to create a holding class for each child node which implements IComparable if the default sort does not achieve what you want. When the ArrayList is sorted, clear the parent node and re-add the child nodes back in in the sorted order.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top