How to automatically select the first item of a popup menu

Asked

Viewed 304 times

0

I have a screen where a popup key is opened through enter as a hotkey. My problem is that I can’t get the first option to be preselected to be activated with a Enter. Summarizing: I would like when displaying the popup to enter "click" on the first popup item.

  • You wanted Enter to select the option or call the event of the first option?... because otherwise you can call the Onclick event from that Popupmenu option by clicking enter.

2 answers

0


After a few more researches and tests I arrived at the following solution. In the event OnPopup enter the 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 from the list. The first line "presses" the button and the second "drops".

0

In his popupMenu add the code below in the event onPopup, that is, when show the popupMenu automatically select the first option:

PopupMenu1.Items[0].Click; 

This way it becomes more dynamic, no matter what method name you call in the first item, it is automatically clicked.

  • 1

    your idea has a problem, like the command you added is in the onPopup it will always be called before the popup itself appears and as said the first option is the most used, but sometimes the necessary is to use another function and not the first.

  • 1

    I’ll see another solution mon.. or Tuesday post

Browser other questions tagged

You are not signed in. Login or sign up in order to post.