LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I detect which items have been selected in a tree

I have a tree control and I have created a callback function for it. I've tried both the EVENT_SELECTION_CHANGE and EVENT_VAL_CHANGED but no matter which one I choose, the function GetTreeItem gives me items from before the value changed and I need the new values. Is there any other event I should be using or any other functions I should be calling?
0 Kudos
Message 1 of 4
(3,395 Views)
I also tried calling ProcessDrawEvents (); but that does not help.
0 Kudos
Message 2 of 4
(3,394 Views)
I have used EVENT_COMMIT and GetActiveTreeItem obtaining the correct index in the list of items. You may also look at treeevent sample project (in \<cvidir>\samples\userint folder) for an example of using EVENT_SELECTION_CHANGE and eventData2.


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 3 of 4
(3,377 Views)
When the tree is in multiple selection mode (which is the default mode), an item being 'active' and an item being 'selected' are two different things. There is always exactly one active item in the tree, while there can be zero or more selected items. When you want to be notified when the active item changes, call GetActiveTreeItem when you receive an EVENT_VAL_CHANGED with eventData1 equal to ACTIVE_ITEM_CHANGE.
 
As for the EVENT_SELECTION_CHANGE, it is swallowable, so the state of the tree can't be changed by the time you receive the event. This is why eventData1 and eventData2 tell you what is about to happen if you do not swallow the event. eventData1 indicates whether the item is being selected or unselected and eventData2 indicates the item.
 
Try adding this to the function treeCallback in the sample code treeevent.c.
 
  case EVENT_VAL_CHANGED:
   if (ACTIVE_ITEM_CHANGE == eventData1)
    {
    GetActiveTreeItem (panelHandle, PANEL_TREE, &activeIndex);
             GetLabelFromIndex (panelHandle, PANEL_TREE, activeIndex, label1);
    Fmt (msg, "%s<%d) EVENT_VAL_CHANGED: '%s' is the new active index\n",
                    eventCnt++, label1);
    SetCtrlVal (panelHandle, PANEL_TEXTBOX, msg);
    }
   break;
0 Kudos
Message 4 of 4
(3,361 Views)