1

I have not been able to figure out why I am unable to manually scroll through a TComboBox component when I programatically cause the drop down pick list to appear. Here is the code I am using:

SendMessage(ComboBox1.handle, CB_SHOWDROPDOWN, Integer(True), 0); 

This causes the drop down pick list to appear. However, if I try to use my keyboard and use the up and down arrow keys, the drop down pick list immediately closes. How do I keep the list from auto-closing when using the keyboard up/down navigation keys?

0

1 Answer 1

5

Activate the ComboBox. And you'd better use the DroppedDown property, which also invalidates the combobox to reflect the change.

ActiveControl := ComboBox1; ComboBox1.DroppedDown := True; 
Sign up to request clarification or add additional context in comments.

4 Comments

Worth noting that OP's CB_SHOWDROPDOWN is only one of a larger set of window messages required to recreate the full sequence of activating and dropping down a combobox (which is why it doesn't work on its own). Agreed that this is preferable approach.
Adding ActiveControl := ComboBox1; and ComboBox1.DroppedDown := True; to the code makes no difference. The drop down list still continues to auto-close as soon as the down arrow key is touched.
@user - With my test here, with a brand new form having a button and a combobox, activating the combobox makes the difference. Actually if I don't activate it, the items cannot be changed with the keyboard but the dropdown doesn't close either. I suggest you to do the same and try this with a new project.
@J... Either will end up in SetActiveControl. To the first comment - Yeah, DroppedDown also invalidates the combo client rectangle. Incorporated to the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.