How to automatically select the first item in a PopupMenu

0

I have a screen where a popupMenu is opened through the enter as a shortcut key. My problem is that I can not make the first option be pre-selected to be activated with an Enter. In short: I would like to display the popupMenu enter to "click" on the first popup item.

    
asked by anonymous 10.03.2017 / 13:59

2 answers

0

After some research and testing, I came up with the following solution. In event OnPopup insert code

keybd_event(VK_DOWN, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);

This code simulates pressing the "down arrow" by selecting the first item in the list. The first line "presses" the button and the second "release".

    
11.03.2017 / 15:28
0

In your popupMenu add the code below in the onPopup event, that is, when you show popupMenu it will automatically select the first option:

PopupMenu1.Items[0].Click; 

That way it gets more dynamic, no matter what the name of the method it will call in the first item, it is automatically clicked.

    
10.03.2017 / 15:02