Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a treeview control on winform application. Here, what I want to do is: Collapse all other nodes at his level and expend only selected node. For example, suppose the scenario:
- All Subject
+ Computer Science
+ Mathematics

Root Node is All Subjects and two child nodes are 1) Computer Science and 2) Mathematics. These two child nodes have further child nodes.

When I select Computer Science, teh Mathematic node should be collapsed and Computer Science Node should be expanded.
How can this be achieved ? Suggestion to accomplish this are welcomed.

Thanks
Posted

1 solution

Suggestion to accomplish this are welcomed.
Just loop though the parent nodes and collapse all leaving the current one!

OR

even better, collapse all and then just expand the current selection.

Following will help:
MSDN: TreeView.CollapseAll Method[^]
MSDN: TreeNode.Collapse Method[^]
MSDN: TreeNode.Expand Method[^]
 
Share this answer
 
Comments
Prasad_Kulkarni 10-Jul-12 6:36am    
A complete 5 worth answer!
Sandeep Mewara 13-Jul-12 3:27am    
Thanks Prasad. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900