Hi,
I want to automatically sort treeviewnodes alphabetically when i add them and want to move them anywhere in treeview.
How this can be done?
Thanks
Smita
Treeview
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jul 5, 2011, 5:17 AM EDT
Just before loading the data to TreeView, sort it.
For moving the node, You need to dynamically create drag & drop event for the node which is parent.
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 5, 2011, 5:28 AM EDT
Set TreeView.TreeViewNodeSorter property to instance of IComparer class (which you might need to code yourself) and TreeView control will keep the nodes sorted at all times. Refer to MSDN article for details: http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.treeviewnodesorter.aspx
If you're only storing strings to the TreeView, then you can use already available StringComparer class to do the comparison, so you need no coding at all. Refer to MSDN article for that too: http://msdn.microsoft.com/en-us/library/system.stringcomparer.aspx
Zoran