Add Method - TreeView Nodes

Add a Node to the tree view control's Nodes collection.

object.Nodes.Add(Text, Icon, SelectedIcon, Relative, Relationship, Key)

Client support

   Newlook Smartclient only.

Parameters

Text - (String, Required)

The display text for the Node.

Icon - (Integer, Required)

The index of the icon to be displayed next to the node. This is the index of an icon in an associated ImageList control assigned to the Icons property of the TreeView control. If there is no ImageList associated with the Icons property of this control, specify an index of 0.

SelectedIcon - (Integer, Required)

The index of the icon to be displayed when the node is selected. This is the index of an icon in an associated ImageList control assigned to the StateIcons property of the TreeView control. If there is no ImageList associated with this control specify an index of 0.

Relative - (Object, Required)

The existing node that this node will be inserted in relation to. It is possible to reference a node by either its key or by using an expression which evaluates to the node (see both methods in the examples below). The Relationship parameter then determines how the new node will be placed in relation to the node specified in this argument. If there are no existing nodes (i.e. the node you are adding is the control's first node) then null should be specified.

Relationship - (String, Required)

Specifies where the new node will be placed in relation to the node specified in Relative. There are five available string values that can be used in this argument:

If there are no existing nodes (this is the first node added to the tree view control) then null should be specified.

Key - (String, Optional)

Assigns a string which can be used to subsequently reference the added node. This value can be used to retrieve the node with the FindByKey method and to specify the Relative argument of subsequent Add calls.

Use

This method adds a node in the position specified. In order to reference an individual node object in subsequent code or via the FindByKey method, it is recommended that you specify a Key parameter.

ALERT !!

It is not possible to specify a relative argument for the Add method that points to existing Nodes created in Designer, as Nodes created in Designer do not have a key. If you want to be able to add or remove nodes at run-time, you will need to populate the tree view control at run-time on the Receive event of the form.

TIP:

If the Clear method has been called prior to the Add method being evoked it may be necessary to use the RefreshForm method to update the control.  

EXAMPLES

The following code will add three levels of Nodes to an empty TreeView control:

JSCRIPT

function AddNodes()

{

//Add the top-level node

nodeCEO = App.ActiveForm.tvOrgChart.Nodes.Add ("CEO", 0, 0, null, null,"nT1");

 

//Add the second tier of nodes

nodeCFO = App.ActiveForm.tvOrgChart.Nodes.Add ("CFO", 0, 0, "nT1", "First","nT21");

nodeCTO = App.ActiveForm.tvOrgChart.Nodes.Add ("CTO", 0, 0, nodeCEO, "Last", "nT22");

 

//Add the third tier of nodes

nodeTL31 = App.ActiveForm.tvOrgChart.Nodes.Add ("Accounts Team Lead", 0, 0, "nT21", "Child","TL31");

nodeTL32 = App.ActiveForm.tvOrgChart.Nodes.Add ("Admin Team Lead", 0, 0, nodeTL31, "Sibling", "TL32");

nodeTL33 = App.ActiveForm.tvOrgChart.Nodes.Add ("QA Team Lead", 0, 0, "nT22", "Sort","TL33");

nodeTL34 = App.ActiveForm.tvOrgChart.Nodes.Add ("Dev Team Lead", 0, 0, nodeCTO, "Sort", "TL34");

 

//Ensure that the control is expanded so that the last node is visible

App.ActiveForm.tvOrgChart.EnsureVisible ("TL34");

}

VB SCRIPT

Sub AddNodes()

'Add the top-level node

nodeCEO = App.ActiveForm.tvOrgChart.Nodes.Add ("CEO", 0, 0, Null, Null,"nT1")

 

'Add the second tier of nodes

nodeCFO = App.ActiveForm.tvOrgChart.Nodes.Add ("CFO", 0, 0, "nT1", "First","nT21")

nodeCTO = App.ActiveForm.tvOrgChart.Nodes.Add ("CTO", 0, 0, nodeCEO, "Last", "nT22")

 

'Add the third tier of nodes

nodeTL31 = App.ActiveForm.tvOrgChart.Nodes.Add ("Accounts Manager", 0, 0, "nT21", "Child","TL31")

nodeTL32 = App.ActiveForm.tvOrgChart.Nodes.Add ("Admin Manager", 0, 0, nodeTL31, "Sibling", "TL32")

nodeTL33 = App.ActiveForm.tvOrgChart.Nodes.Add ("QA Mnager", 0, 0, "nT22", "Sort","TL33")

nodeTL34 = App.ActiveForm.tvOrgChart.Nodes.Add ("Dev Manager", 0, 0, nodeCTO, "Sort", "TL34")

 

'Ensure that the last node is visible when the object is displayed

App.ActiveForm.tvOrgChart.EnsureVisible "TL34"

End Sub

See Also

RefreshForm Method | Clear Method | Remove Method | Aid Key Constants | AddNew method | AddItem method | AddRecord method | Node object | ListItem object | ColumnHeader object | Add Method - Function Keys | Add Method - Controls | Add Method - ColumnHeaders | Add Method - Items

Applies To

Nodes collection


© 2004-2021 looksoftware. All rights reserved.