Question Add tree nodes

look4guna

Member
Joined
Oct 9, 2008
Messages
18
Programming Experience
Beginner
hi!

i want to create an treeview control which has these features.

user have to enter how many nodes he wants.

after he entered the code should generate nodes in the treeview as per the text box.


can any one help to get out this problem?

OR

can any one tell me how to create treeview and root node which has sub node.

example:

ROOTNODE
'
'--SUBNODE 1
'
'--SUBNODE 3
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,334
Location
Norway
Programming Experience
10+
You should read the documentation for the TreeView class and related classes you may encounter, especially the TreeNode class and the TreeNodeCollection class.
I have linked to online version of main help page for Treeview class, but using your local help is much much faster and better.
 

look4guna

Member
Joined
Oct 9, 2008
Messages
18
Programming Experience
Beginner
thanks johnH, that msdn thread is very useful!

its working well!!
 

look4guna

Member
Joined
Oct 9, 2008
Messages
18
Programming Experience
Beginner
Retrieve no of child nodes

Hi friends!

can u tell me how to retrive the child nodes under a root node.

for example , i

root node
'
'
'--subnode1
'
'--subnode2
'
'--subnode3

when i click on the root node it should retrive the result as 3


can anyone help me?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,334
Location
Norway
Programming Experience
10+
Doubleclick the TreeView control the default event handler AfterSelect is generated, as it happens to be this event suits you fine. With the code examples for this and other Treeview events you have seen that e.Node give you the node in question. You also know that each TreeNode has a Nodes property that contains the child nodes of this node, this property is a TreeNodeCollection. Like any other collection it has a Count property that tell you how many items it contains. Putting this information together with one "." between each part you get the final answer: e.Node.Nodes.Count
 

look4guna

Member
Joined
Oct 9, 2008
Messages
18
Programming Experience
Beginner
Thanks john!.

i solved this problem, but the idea is yours.

integer = e.node.getnodecount(true)


the above code stores the node count into an integer...
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,334
Location
Norway
Programming Experience
10+
Great, but GetNodeCount method with True parameter also includes nodes of the full subtree, which is not what you asked. Giving False parameter will give same result as Nodes.Count.
 

look4guna

Member
Joined
Oct 9, 2008
Messages
18
Programming Experience
Beginner
how to get childnodes names of a parent node

hi friends! i have to show the names sub nodes of currently selected node?

can anyone help me?
 
Top Bottom