subscribe to the NodeMouseClick event on the treeview and add the code below
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();
}
}
}
}