Closing Treeview nodes automatically
Closing Treeview nodes automatically
am 28.10.2007 17:26:25 von AJJ
Hello,
I have a TreeView control with "top-level" nodes and "second-level" nodes
(probably not the correct terms) as follows:
objNode = new TreeNode();
objNode.Text = "2006";
objNode.SelectAction = TreeNodeSelectAction.Expand;
tvSide.Nodes.Add(objNode);
objChildNode = new TreeNode();
objChildNode.Text = " ·January";
objChildNode.NavigateUrl = "../2006/jan.aspx";
objNode.ChildNodes.Add(objChildNode);
objChildNode = new TreeNode();
objChildNode.Text = " ·February";
objChildNode.NavigateUrl = "../2006/feb.aspx";
objNode.ChildNodes.Add(objChildNode);
// other child nodes for 2006
objNode = new TreeNode();
objNode.Text = "2007";
objNode.SelectAction = TreeNodeSelectAction.Expand;
tvSide.Nodes.Add(objNode);
objChildNode = new TreeNode();
objChildNode.Text = " ·January";
objChildNode.NavigateUrl = "../2007/jan.aspx";
objNode.ChildNodes.Add(objChildNode);
objChildNode = new TreeNode();
objChildNode.Text = " ·February";
objChildNode.NavigateUrl = "../2007/feb.aspx";
objNode.ChildNodes.Add(objChildNode);
When I click on the 2006 node, it correctly expands to reveal the nodes
underneath it.
But, if I then click on the 2007 node, I would like it to "close up" the
2006 node as well as expanding the 2007 node. Is there a way to do this?
Thank you.
DJ
RE: Closing Treeview nodes automatically
am 28.10.2007 23:32:00 von Geo
Hi, I have done this in Javascript. You can actually view source of the page
and write a generic code to handle it.
-Geo.
"David Jackson" wrote:
> Hello,
>
> I have a TreeView control with "top-level" nodes and "second-level" nodes
> (probably not the correct terms) as follows:
>
> objNode = new TreeNode();
> objNode.Text = "2006";
> objNode.SelectAction = TreeNodeSelectAction.Expand;
> tvSide.Nodes.Add(objNode);
>
> objChildNode = new TreeNode();
> objChildNode.Text = " ·January";
> objChildNode.NavigateUrl = "../2006/jan.aspx";
> objNode.ChildNodes.Add(objChildNode);
>
> objChildNode = new TreeNode();
> objChildNode.Text = " ·February";
> objChildNode.NavigateUrl = "../2006/feb.aspx";
> objNode.ChildNodes.Add(objChildNode);
>
> // other child nodes for 2006
>
> objNode = new TreeNode();
> objNode.Text = "2007";
> objNode.SelectAction = TreeNodeSelectAction.Expand;
> tvSide.Nodes.Add(objNode);
>
> objChildNode = new TreeNode();
> objChildNode.Text = " ·January";
> objChildNode.NavigateUrl = "../2007/jan.aspx";
> objNode.ChildNodes.Add(objChildNode);
>
> objChildNode = new TreeNode();
> objChildNode.Text = " ·February";
> objChildNode.NavigateUrl = "../2007/feb.aspx";
> objNode.ChildNodes.Add(objChildNode);
>
> When I click on the 2006 node, it correctly expands to reveal the nodes
> underneath it.
>
> But, if I then click on the 2007 node, I would like it to "close up" the
> 2006 node as well as expanding the 2007 node. Is there a way to do this?
>
> Thank you.
>
> DJ
>
>
>
Re: Closing Treeview nodes automatically
am 29.10.2007 12:20:51 von AJJ
"Geo" wrote in message
news:F9A8F338-9DE7-4C91-AD80-A1C53FFAA8E1@microsoft.com...
Hello Geo,
> Hi, I have done this in Javascript. You can actually view source of the
> page
> and write a generic code to handle it.
Excellent suggestion! The following code will do this, if anyone else is
interested:
N.B. this could probably be made more robust by checking that the id of the
children element ends with 'Nodes' rather than just contains 'Nodes', and
the TreeView_ToggleNode function does a fair bit more than just setting the
display style, but the above works for me and is all I need at the moment.
DJ
Closing Nodes upon Selection of anotherone
am 05.12.2007 21:31:28 von unknown
Hi guys. I have a treeview that should close is nodes when one of them is expanded just as this example. But there is a "catch"-
My treeview structure is as follows
RootNode
--------Child1
----------Sub1Child1
----------Sub1Child2
--------Child2
----------Sub2Child1
----------Sub2Child2
If I expand Sub1Child1 then Sub1Child2 and Child2 should be Collapsed.
Can you give me a hand here? I've been trying to do this for some time now and got no results :S
Thanks
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
RE: Closing Nodes upon Selection of anotherone
am 10.01.2008 16:47:04 von Geo
Hi, Just wondering whether you got to do this. If not let me know and I can
help you. I did the same in one of my projects.
Thanks
Geo.
"Matias Banzas" wrote:
> Hi guys. I have a treeview that should close is nodes when one of them is expanded just as this example. But there is a "catch"-
>
> My treeview structure is as follows
>
> RootNode
> --------Child1
> ----------Sub1Child1
> ----------Sub1Child2
> --------Child2
> ----------Sub2Child1
> ----------Sub2Child2
>
> If I expand Sub1Child1 then Sub1Child2 and Child2 should be Collapsed.
>
> Can you give me a hand here? I've been trying to do this for some time now and got no results :S
>
> Thanks
>
> EggHeadCafe - .NET Developer Portal of Choice
> http://www.eggheadcafe.com
>