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