Tips_gui   >   Treelists   >   Tree Node Methods & Properties

Tree Node Methods & Properties

This section covers various methods and propeties of the treelist nodes. Tips, sample code, and demos let you see how to make use of the methods and properties when working with the treelist object.

You can find information in the F1 Help on treelist nodes by searching for tree node.

Be sure to review the Treelist Naming Conventions topic if you haven't already done so.

A Run Demo button will appear at the bottom of the StudioTips Browser window if a demo is available for a particular tip. Clicking the Run Demo button will open up a demo window.

For most of the demos in this section, you can play around clicking on different nodes in the treelist and then clicking the pushbutton to test the method on different nodes.

Holding down the shift key while clicking the button in the demo window will take you to a breakpoint in the method code allowing you to step through the actual code so you can see what is happening behind the scenes.

Note

You do not need to issue a $redraw after using a treelist method. Each treelist method automatically redraws the treelist object when applicable.

$checked

If true, the line is checked.

If rNode.$checked
   ; Do something.
Else
   ; Do something else.
End If

$drawinactive

If true, the text for the node is drawn to indicate that the node is not active, and the expand/collapse box is hidden.

$enterable

If true, the grid is enterable.

$iconid

The numeric icon identifier used to reference the icon in the icon file or #ICONS.

; Set the icon ID for the node.
Do rNode.$iconid.$assign(1704)
; or
Calculate rNode.$iconid as 1704

$isexpanded

If true, the node is already expanded.

If rNode.$isexpanded
   ; Do something
Else
   ; Do something else.
End If

$level

The node indent level within the tree.

; Find out the indent level of the specified node.
Do rNode.$level() Returns LevelNum
; or
Calculate LevelNum as rNode.$level()

; Decide what to do based on the indent level of the node.
Switch rNode.$level
   Case 1
      ; Do something
   Case 2
      ; Do something else
End Switch

$nodeparent

Returns a tree node item reference to the parent node of the current node. If the return value is empty, then the current node is a root node.

; Get a reference to the node's parent.
Do rNode.$nodeparent() Returns rParentNode

$rowdata

The row variable containing the column data for the node, used when the tree list has more than one column. Column N of the row variable contains the data of column (N + 1) of the tree list. Each column is a character string of up to 255 characters.

; Set the row data.
Do rNode.$rowdata.$assign(Row)

; Get the row data.
Do rNode.$rowdata Returns Row

$seedid

A unique number assigned to a node within a tree. This is a read-only property.

Calculate ID as rNode.$seedid

$selected

Setting the treelist property $multipleselect property to kTrue allows the user to select multiple nodes in the treelist.

If the $selected treelist object property has been set to kTrue node is selected. You can $assign the $selected property of any node.

If rNode.$selected
   ; The node is selected.
End If

$showexpandalways

If true, the node is to always show the expand/collapse box.

Do rNode.$showexpandalways.$assign(kTrue)

$tag

Omnis introduced a $tag treelist node property which can be assigned by the developer. The $tag property is a binary, so you can assign any datatype to the $tag node property.

I have found the $tag node property great for building treelists on-the-fly. For example if I build a treelist of all the classes in a library, as the list is built, I assign a class item reference to each node's $tag property. When the user clicks to expand a class node, I simply use $tag property to get the item reference to the class. With the class reference in hand, a list of methods for that class can be very quickly built and the method name nodes added. As each method node is added, the method item reference is assigned to the node's $tag property.

; Build a treelist which displays all the menu classes in the current library.

; Clear all the treelist nodes.
Do irTreeObj.$clearallnodes()

; Make a list of all the menu classes in the current library.
Do $clib.$menus.$makelist($ref().$name,$ref) Returns ClassesList
Do ClassesList.$cols.1.$name.$assign('name')
Do ClassesList.$cols.2.$name.$assign('ref')

; Loop through the classes list, building the treelist root nodes.
For ClassesList.$line from 1 to ClassesList.$linecount step 1
   
   ; Add the root node and set the $tag to reference the class.
   Do irTreeObj.$add(ClassesList.name) Returns rNode
   Do rNode.$showexpandalways.$assign(kTrue)
   Do rNode.$tag.$assign(ClassesList.ref)
   
End For

Quit method kTrue

; The following code would be used in the $event method of the treelist object.
On evTreeExpand
Switch pNodeItem.$level
   Case 1 ;; Class
      
      ; Clear the existing child nodes.
      Do pNodeItem.$clearallnodes()
      
      Set reference rClass to pNodeItem.$tag().$ref
      
      ; Make a list of the methods and add them as child nodes.
      Do rClass.$methods.$makelist($ref().$name,$ref) Returns MethodsList
      Do MethodsList.$cols.1.$name.$assign('name')
      Do MethodsList.$cols.1.$name.$assign('ref')
      For MethodsList.$line from 1 to MethodsList.$linecount step 1
         
         Do pNodeItem.$add(MethodsList.name) Returns rNode
         Do rNode.$tag.$assign(MethodsList.ref)
         
      End For
      
   Case 2 ;; Method.
      
      
End Switch

Use your imagination. The $tag property can help with building treelists on-the-fly and save a lot of code.

Warning

The $tag property can not be saved back to any of the nodes lists (kFlatList,kTreeColsList,kTreeRelationalList). If you need to save the $tag value to a nodes list considering adding/using a column in the $rowdata property instead.