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
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Zoran HorvatPosted Jul 5, 2011, 9:28 AM
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
Jaganathan BantheswaranPosted Jul 5, 2011, 9:17 AM
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.