LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Call GetActiveTreeItem() cannot capture the right tree item.

I have created a tree control which has 14 items. When using the mouse to click the tree's bottom  space , and using the GetActiveTreeItem()  to check the index value, I have got the last item's index. I hope if  not click any item the application will be nothing to do. Please give an advise. (CVI 2010 sp1)

 

 

David

0 Kudos
Message 1 of 7
(3,498 Views)

David,

 

Clicking on the empty space does not change the active item of the tree, so it's not surprising that GetActiveTreeItem returns the same index that it was returning before your mouse click.

 

You might be confusing "active item" with "selected item". Clicking on the empty item does remove the selection/highlight from any items which were previously selected/highlighted. To obtain the selection state for each item you can use the following call on each item:

 

GetTreeItemAttribute (panel, control, itemIndex, ATTR_SELECTED, &selectedState);

 

Luis

0 Kudos
Message 2 of 7
(3,493 Views)

Thank you for your reply. That is good idea.

 

 

David

0 Kudos
Message 3 of 7
(3,486 Views)

Hi Luis,

 

I've tried the method but cannot satisfiy my design. There are 14 items in the tree, whatever I do something as long as clicked the tree bottom, I have got the last item data. Due to  the last item is a useable data and I hope just really point it then can read the item, so I'd like to know what method can get the correct goal?

 

 

David

0 Kudos
Message 4 of 7
(3,479 Views)

What method can be used to determine if the clicked is an invalid area?

0 Kudos
Message 5 of 7
(3,477 Views)

You may have some guidance by looking at samples\userint\treeevent CVI example: when clicking on the blank part of the tree you can handle the EVENT_SELECTION_CHANGE and discriminate on eventData1 whether an actual item was clicked or not.

 

Here an abstract from the tree control callback in that example:

 

        case EVENT_SELECTION_CHANGE:            
            GetLabelFromIndex (panelHandle, PANEL_TREE, eventData2, label1);
            if (eventData1)
                Fmt (msg, "%s<%d) EVENT_SELECTION_CHANGE: '%s' has been selected\n", 
                    eventCnt++, label1);
            else
                Fmt (msg, "%s<%d) EVENT_SELECTION_CHANGE: '%s' has been unselected\n", 
                    eventCnt++, label1);
            SetCtrlVal (panelHandle, PANEL_TEXTBOX, msg);
            break;

 You can try swallowing that event and see if this solves your situation (i.e. no other events are received by the control callback).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 7
(3,473 Views)

And if you really just want to know where the user clicked, you can use the GetIndexFromPoint function.

 

 

 

Message 7 of 7
(3,467 Views)