LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to display a seperate right click menu for each item of a tree control?

Hi I want to display a specific right click menu when a particular tree item is selected. I know how to create a menu and how to display it. I am using the function GetLabelFromIndex() to get the active tree item and then compare the label and based on the result display a manu for that item. Now my problem is that when I use the above function in the EVENT_RIGHT_CLICK it gives me the error "the Index passed is out of range" while using the same function with the same arguments in EVENT_SELECTION_CHANGE it gives no error...below is the part of my code

case EVENT_RIGHT_CLICK:
   GetLabelFromIndex(panelHandle, PANEL_TREE, eventData2, label1);
         //The function gives the stated error here
   if(eventData1)//after it I compare the result and display the menu  

case EVENT_SELECTION_CHANGE:
   GetLabelFromIndex (panelHandle, PANEL_TREE, eventData2, label1);
        //The function works fine here 
     if (eventData1)  
                 

 If any one have any idea whats going on or alternate way of doing this Please share knowledge...Thanks

If you are young work to Learn, not to earn.
0 Kudos
Message 1 of 4
(3,381 Views)

You have two options:

 

1) You can use EVENT_CTRL_MENU to customize the built-in right click menu of the tree control based on the active tree item (or group of selected tree items). Check out samples/userint/treemenu.

 

2) Turn off the tree's built-in right click menu (with ATTR_ENABLE_POPUP_MENU) and create your own menu and display it with RunPopupMenu on EVENT_RIGHT_CLICK and EVENT_KEYPRESS when eventData1 == VAL_POPUP_MENU_VKEY

0 Kudos
Message 2 of 4
(3,377 Views)

Thank you for ur support. I am using the second method to display different menu for different tree items. but my question is why I get the error when I right click anywhere in the tree. 

If you are young work to Learn, not to earn.
0 Kudos
Message 3 of 4
(3,366 Views)

Hi,

 

one possible approach of solving this problem is looking closer at the error message: The error "the Index passed is out of range" tells you that something is wrong with the index, either it is too small or too large Smiley Wink So why don't you set a breakpoint and check the index value, it might be useful information...

 

The other hint is to check the meaning of eventdata2 (using the help): It is different for different events! For the event_right_click it gives the horizontal mouse position, not the index as event_selection_change does...

0 Kudos
Message 4 of 4
(3,362 Views)