473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Closing Treeview nodes automatically

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
Oct 28 '07 #1
2 1605
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
Oct 28 '07 #2
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
Jan 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Goldin | last post by:
Anybody can shart some working samples of using that control on Windows form? Thanks
1
by: Lanny McDonald | last post by:
I have built a treeview that looks something like: Root .....FolderLevel1a .........FolderLevel2a
3
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with...
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
0
by: Treeview Trouble | last post by:
I have an application where there are two radio buttons each of which populates a treeview control with a directory structure. Each radio button corresponds to a different directory which may or...
5
by: Paul | last post by:
Hi, I am a self taught VBA programmer, and I'm trying to learn VB2005 Express (The price was right). I like the look of the treeview control, and I'd like to use it as a menu system for my users,...
4
by: John Dann | last post by:
I'm trying to implement a fairly simple Treeview procedure but running into problems. My Treeview has just two levels of nodes: top-level and one child level. I want a doube-click on the...
26
by: JJ | last post by:
Is there any way you can expand a parent node on the treeview control _without a postback_ by clicking on the node text (NOT clicking the expand image URL) ? I want to format the treeview node...
2
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
Now we have to load the whole company's organizational relationships into one TreeView which has at lest 6~7 layer and including 300~400 nodes.In every node,there is a checkbox. So we need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.