LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Traverse a tree control

Hello,

I make a tree control with cvi 8.5, this tree using some nodes to describe some subjection relations, that means each node has some children items, and click the the plus sign left on the node can be make the node to be expanded  or folded. The question is : how to locate the node but skip its child iterms? I do not know how to  handle "GetTreeItem()" to navigate the parent node, hope can get an advise. Thanks.



David
Message 1 of 3
(3,781 Views)

To get the current tree item I find the get method is to use the methods:
GetIndexFromPoint
GetValueFromIndex

I have tried other methods, even using deffered callbacks and had issues with getting the last value the user clicked on and not the current one.

To skip the child when you use GetTreeItem set the relation to sibling.

 

Message 2 of 3
(3,759 Views)
If you want to iterate over your root items, you would call GetTreeItem in a loop like this:

for (err = GetTreeItem(panel, ctrl, VAL_SIBLING, 0, VAL_FIRST, VAL_NEXT_PLUS_SELF, 0, &index);
      err >0 && index != -1;
      err = GetTreeItem(panel, ctrl, VAL_SIBLING, 0, index, VAL_NEXT, 0, &index)) { ... }

Take a look at GetTreeItem's function panel for names and detailed descriptions of each parameter. In this example, the relation parameter (VAL_SIBLING) indicates that you are looking only for items at the same level in the tree. The relative index (0) is the index whose siblings you are searching for. Begin index is the tree item that you will begin searching from. When you first call this function, you pass VAL_FIRST to start with the first matching item, then subsequent calls pass index to continue the search from the previously returned index. The direction parameter is VAL_NEXT_PLUS_SELF if the begin index needs to be processed, or it is VAL_NEXT if the passed begin index has already been processed and so shouldn't be returned again.

Hope this helps.

Mert A.
National Instruments
Message 3 of 3
(3,754 Views)