Programming Guide : Working with List Views and Tree Views : TreeNode and Tree Classes : Tree Class
 
Share this page          
Tree Class
The Tree class is used to manage data that has an hierarchical structure. A tree contains a collection of treenode objects. The top treenode in the hierarchy is the root node. The following sections describe its attributes and methods.
Attributes
The Tree class has two attributes:
RootNode
Specifies the tree's root node
Nodes
Specifies the total number of nodes in the tree
Maintenance Methods
Use the following methods to maintain the tree:
AddNode
Adds a node to the tree
DeleteNode
Deletes a node from the tree
Node Location Methods
Use the following methods to find nodes in a tree:
NodeByName
Finds a node with a given name, or TextLabel
NodeByKey
Finds a mode with a given key. When you add a node to a tree, you may specify a unique key. The NodeByKey method is useful when the nodes in a tree do not have a unique name, and the NodeByName method does not find a unique node.
Traversal Methods
The following methods let you traverse the entire tree:
StartTraverse
Lets you traverse the entire tree
NextNode
Returns the next node after you have started to traverse the tree
StopTraverse
Stops the traverse operation
AddNode Method
The AddNode method creates a node and adds it to the tree. It is the basic method for building a tree.
This method has the following syntax:
treenode = tree.AddNode
(
     name         = varchar(256),
     [keylabel     = varchar(256),]
     [relative     = treenode,]
     [relation     = integer]
);
The AddNode method has one mandatory parameter, and three optional parameters:
name
(Required) Specifies the node's TextLabel attribute
keylabel
(Optional) Lets you specify a unique string that is associated with the new node. If you specify a key label, you may use the NodeByKey method to search for the node.
relative
(Optional) Specifies an existing node in the tree. If relative is not specified or is null, the new node becomes the root node of the tree; the old root node, if it exists, becomes a sibling of the new root node.
relation
(Optional) Specifies the relation of the new node to relative. The possible values of relation are:
TN_LASTCHILD
Specifies that the new node is the last child of relative. This is the default if relation is not specified.
TN_FIRSTCHILD
Specifies that the new node is the first child of relative
TN_NEXTSIBLING
Specifies that the new node is the next sibling of relative
The AddNode method returns the newly created node.