LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Right-click menu (context menu) with a list box

Hello,

I've just created a right click menu for a list box control as described here:
http://sine.ni.com/devzone/cda/epd/p/id/959
The menu contains some entries for renaming and deleting an element of the list box.

Now I have the problem to recognize on which list box entry the user has clicked the right mouse button.
With the left mouse button you can select an entry (EVENT_VAL_CHANGED) and recognize it with the GetCtrlValue(). But the value doesn't change if the user clicks the right mouse button.

How can I solve this problem, so that at a right mouse click first the list box selection changes before the context menu will be displayed.
(compare to the Windows Explorer: if I right-click on a file the selection switches to this file, and then the context menu appears.)

Best regards,

Martin
0 Kudos
Message 1 of 6
(5,069 Views)

You have a couple of options.

1) You can use a tree control and configure it to look just like a listbox. This way has some advantages:

- the tree behaves just like you want on a right click... it changes the active item on a right click, then pops up the context menu.

- it has it's own customizable right click context menu, so you don't have to use RunPopupMenu

- other additional functionality such as tooltips, horizontal scrollbar, etc. Check out http://forums.ni.com/ni/board/message?board.id=180&message.id=13541#M13541

 

2) Use GetIndexFromPoint in the right click event to get which listbox item was clicked on, make it the active one, then call RunPopupMenu.

 

Hope this helps

- jared

Message 2 of 6
(5,050 Views)
Hi jared,

thank you very much. The function GetIndexFromPoint is exactly what I was looking for.
I ought to be ashamed of myself because I didn't found this function. 😉
Maybe it was friday...

The first option to use a tree control I had already checked. But I think there will be too many changes to my code.

Best regards,

Martin
0 Kudos
Message 3 of 6
(5,019 Views)

Hi Martin,

 

Were you able to implement the code to rename or delete the list box items using a custom right-click menu?

0 Kudos
Message 4 of 6
(2,524 Views)

You are not expected to get an answer from Martin, who has not been visiting this site for 11 years!

Nevertheless GetIndexFromPoint  is supposed to be the right path to go: have you tried implementig it? We can try helping you if you can post your code pointing out where you are getting problems.



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?
Message 5 of 6
(2,495 Views)

Thanks for replying Roberto. So I was able to get it implemented using the other example shared on the forum. 

 

Regards,

0 Kudos
Message 6 of 6
(2,475 Views)