Treeview SIMPLY!

G

Guest

Ok. I have trawled through numerous articles and still cant grasp this
Treeview malarky!!!

I am stumbling more or less at the 1st hurdle so need some simple answers:

1. What is the syntax for the Nodes.Add command?

2. How do I add a root node?

3. How do I add a branch to the root node?

4. How do I add a branch to the branch created in question 3?

I think I can work out how to populate the treeview using my recordsets, if
only I understood how to add nodes/branches/branches off branches properly.

Can anyone clear this up for me? Simple examples will do, the rest I should
be able to work out.

Cheers for listening to my plea.
Steve.
 
D

Douglas J. Steele

Answers in-line.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


FBxiii said:
Ok. I have trawled through numerous articles and still cant grasp this
Treeview malarky!!!

I am stumbling more or less at the 1st hurdle so need some simple answers:

1. What is the syntax for the Nodes.Add command?

object.Add(relative, relationship, key, text, _
image, selectedimage)

Where:
- object is an object expression that evaluates to the Nodes collection of a
Treeview object.
- relative is the index number or key of a pre-existing Node object. The
relationship between the new node and this pre-existing node is defined by
the next argument, relationship.
- relationship specifies the relative placement of the Node object (as
described in below).
- key is a unique string that can be used to retrieve the Node with the Item
method.
- text is the string that appears in the Node.
- image is he index of an image in an associated ImageList control.
- selectedimage is the index of an image in an associated ImageList control
that is shown when the Node is selected

All of the parameters are actually optional (only Object is required)

Valid values for relationship are:

tvwFirst: The Node is placed before all other nodes at the same level of the
node named in relative.
tvwLast: The Node is placed after all other nodes at the same level of the
node named in relative. Any Node added subsequently may be placed after one
added as Last.
tvwNext: he Node is placed after the node named in relative. (this is the
default)
tvwPrevious: The Node is placed before the node named in relative.
tvwChild: The Node becomes a child node of the node named in relative

Note that not only does key have to be a unique string, but it must have at
least one letter in it. (If it were all numbers, it wouldn't be possible to
distinguish it from the node number)
2. How do I add a root node?

Assuming your TreeView control is named "tvDetails", and you want the root
node to read Root:

Me.tvDetails.Nodes.Add _
Key:="Root", _
Text:="Root"

Note that I've defined the key for the node to be Root as well
3. How do I add a branch to the root node?

You don't add "branches" per se: you add a node and position it as a child
of the root. Again, assuming your TreeView is named "tvDetails" and you want
the new node to be named Child1:

Me.tvDetails.Nodes.Add _
Relative:="Root", _
Relationship:=tvwChild, _
Key:="Child1", _
Text:="Child1"
4. How do I add a branch to the branch created in question 3?


Again, assuming your TreeView is named "tvDetails" and you want the child
node of Child1 to be named Child2:

Me.tvDetails.Nodes.Add _
Relative:="Child1", _
Relationship:=tvwChild, _
Key:="Child2", _
Text:="Child2"

Note that how the tree actually appears depends on the values of the Style
and LineStyle properties for the control.

Valid values for Style are:

tvwTextOnly: Text only.
tvwPictureText: Image and text.
tvwPlusMinusText: Plus/minus and text.
tvwPlusPictureText: Plus/minus, image, and text.
tvwTreelinesText: Lines and text.
tvwTreelinesPictureText: Lines, image, and text.
tvwTreelinesPlusMinusText: Lines, plus/minus, and text.
tvwTreelinesPlusMinusPicture: (Default) Lines, plus/minus, image, and text.
(default)

Assuming that the Style is set to a style that includes lines (one of the
last 4), the LineStyle property determines how the lines appear. Valid
values for LineStyle are:

tvwTreeLines: Tree lines. Displays lines between Node siblings and their
parent Node. (default)
tvwRootLines: Root Lines. In addition to displaying lines between Node
siblings and their parent Node, also displays lines between the root nodes



A good reference is
http://msdn.microsoft.com/library/en-us/cmctl198/html/vbobjtreeview.asp
 
G

Guest

Thanks for the reply.

I guess there is no simple answer!!! Your post has helped me to understand
things a bit better.

I have actually managed to begin populating the treeview with the required
information.

I am sure I will have a few more questions in the near future :)

Cheers,
Steve.
 

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