How to expand only the selected node in treeview control?
I have a treeview control. By default the treeview expands and shows all its child nodes. I need to show only the node that is selected.
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.
Vishnu BhangalePosted Mar 3, 2015, 5:20 AM
Khargesh RajputPosted Mar 3, 2015, 5:13 AM
http://www.dotnetsharepoint.com/2014/04/click-node-text-to-expandcollapse.html
http://forums.asp.net/t/1194490.aspx?Treeview+Navigation+Expand+and+Collapse+on+Node+click
Deepa SudhirPosted Mar 3, 2015, 4:42 AM
Khargesh RajputPosted Mar 3, 2015, 4:34 AM
or visit link
http://www.dotnetcurry.com/showarticle.aspx?ID=257
Deepa SudhirPosted Mar 3, 2015, 4:31 AM
Khargesh RajputPosted Mar 3, 2015, 4:15 AM
but after bind treeview
try once
TreeViewArtMaterial.CollapseAll();
and below link may help you
http://www.dotnetcurry.com/showarticle.aspx?ID=257
Deepa SudhirPosted Mar 3, 2015, 4:04 AM
Is there any other property to be set here?
Khargesh RajputPosted Mar 3, 2015, 3:59 AM
{
if (e.Node.Parent == null)
return;
string strNodeValue = e.Node.Value;
foreach (TreeNode node in e.Node.Parent.ChildNodes)
{
if (node.Value != strNodeValue)
node.Collapse();
}
}
working fine for me
Deepa SudhirPosted Mar 3, 2015, 3:51 AM
It works fine only for the first node and its children.
Khargesh RajputPosted Mar 3, 2015, 3:44 AM
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (e.Node.Parent == null)
return;
string strNodeValue = e.Node.Value;
foreach (TreeNode node in e.Node.Parent.ChildNodes)
{
if (node.Value != strNodeValue)
node.Collapse();
}
}
Deepa SudhirPosted Mar 3, 2015, 3:30 AM
Deepa SudhirPosted Mar 3, 2015, 3:27 AM
Khargesh RajputPosted Mar 3, 2015, 12:06 AM
see demo with source code.
http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu-bullet.htm
http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm
Manish Kumar ChoudharyPosted Mar 2, 2015, 11:43 PM
Go through following articles it will help you
http://stackoverflow.com/questions/14596723/how-can-i-get-all-expanded-nodes-in-treeview
https://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.checkboxes%28v=vs.110%29.aspx
http://www.codeproject.com/Questions/196856/C-NET-Treeview-Node-Checked