Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Collapse Other Nodes of TreeView on Selection of One Node.

Thanks,
Murthy.
Posted
Comments
WajihaAhmed 31-Dec-12 3:59am    
What have you tried?

1 solution

subscribe to the NodeMouseClick event on the treeview and add the code below

C#
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
    if (e.Node != null)
    {
        foreach (TreeNode tn in (e.Node.Parent != null ? e.Node.Parent.Nodes : treeView1.Nodes))
        {
            if (tn != e.Node)
            {
                tn.Collapse();
            }
        }
    }
}
 
Share this answer
 

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