Add method in the treeview control

E

Ernest Cook

Does anyone have any real world experience using the .Net version of the
treeview control? If so, Can you recommend any good documentation sources
for learning more about it. i.e. Methods, etc.

I have a few different samples projects and am looking for many more to help
me understand everything I can about it.

One of my current issues is in trying to add a node. I use the ADD method
but under the .net version, you MUST add the node under the parent which
assumes you have a reference to the node collection:
(i.e tvParentNode.Add ("New child Node description")

If I don't have reference to the parent node, how do i get it?
tvOntheForm.Nodes() requires an integer. I know the value I put in the
description, but the index can change ?
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Ernest,

I have been using the WinForms TreeView in several real-world projects (see
the one in my signature, for example) and it works fine. I actually haven't
used anything except the MSDN library as the documentation.
One of my current issues is in trying to add a node. I use the ADD method
but under the .net version, you MUST add the node under the parent which
assumes you have a reference to the node collection:
(i.e tvParentNode.Add ("New child Node description")

This is simple. You first instantiate the parent (that is, root node):

Dim rootNode As TreeNode = New TreeNode(...) ' Specify node text etc. in the
arguments

Then, you add childs to that parent - you already know how this is done.

And finally, you attach the root to the tree itself:

treeView.Nodes.Add(rootNode)

P.S. The biggest difference between the .NET TreeView and the VB6 one is
probably that you are not stuck to the Add method to create new nodes - you
just can instantiate them directly.
 
C

Cor

Hi Ernst,

The treeview is a nice thing to use.

What you have to remember is that it is not anymore a one part control, but
that there are two parts, the root and the node. (Treeview and treenodes)

What you are doing all the time is hanging (adding) nodes in a node and
those nodes again in the tree.

When you are used to, it is quiet easy. There is a lot of documentation
about it on MSDN.

The listview works in the same way; you can build your own explorer in no
time with those two. I hope this gives you some understanding about the
treeview.

I hope this helps a little bit
Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top