04-10-2013 12:00 PM
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
04-10-2013 01:39 PM
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
04-10-2013 06:41 PM
Thank you for your reply. That is good idea.
David
04-11-2013 12:23 AM
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
04-11-2013 01:21 AM
What method can be used to determine if the clicked is an invalid area?
04-11-2013 01:59 AM
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).
04-11-2013 09:43 AM
And if you really just want to know where the user clicked, you can use the GetIndexFromPoint function.