Forcing List to Drop

I have loaded a ComboBox with several items. When running, if I click on the down arrow the items will display in the drop down list box OK and the user can select an item..What code do I use to have the program show the drop down list automatically so the user does not have to click the down arrow to display the list?

I know of a couple of ways to do this. The first uses a combo box with the “style” property set to “0”. Put the following constants in your declaration section:

Put the following functions in your declaration section:
Declare Function SendMessageByString Lib “user” Alias “SendMessage” (ByValhWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam$) As LongDeclare Function SendMessageByNum Lib “user” Alias “SendMessage” (ByValhWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam&) As Long
Put the following code in your combo box’s keypress event:
Dim flgIsdropped As IntegerDim lngRetval As Long’if return was pressed, then set the combobox.listindex to the first match in the list ‘The parameters (in order) are: window handle to the combo box, constant ‘to find the first match in the list, the list position to start the ‘search from, the text to search for.If KeyAscii = 13 Then   combobox.ListIndex = SendMessageByString(combobox.hWnd, CB_FINDSTRING, 0,combobox.Text)   Exit SubEnd If’if the list box is not already dropped, then drop it ‘returns nonzero if list box is dropped, zero otherwiseflgIsdropped = SendMessageByNum(combobox.hWnd, CB_GETDROPPEDSTATE, 0, 0)If Not flgIsdropped Then    ‘set third paramater to true to show dropdown box, false to hide it    lngRetval = SendMessageByNum(combobox.hWnd, CB_SHOWDROPDOWN, True, 0)End If
Put the following code in your combo box’s lostfocus event:
combobox.ListIndex = SendMessageByString(combobox.hWnd, CB_FINDSTRING, 0,combobox.Text)
This code checks to see if the list box has already been dropped and drops it if need be. Once the list box gets dropped, Windows takes care of moving the list around to seek an entry that matches what the user has typed. Thedisadvantage to using this method is that even though Windows displays the entry that matches the typed string, I don’t know how to get Windows to highlight the entry. If anybody knows how to do this, I would like to hear about it. The other option is to use a text box and a list box. Put the following code in the text box’s change event:
listbox.ListIndex = SendMessageByString(combobox.hWnd, LB_FINDSTRING, 0,combobox.Text)(LB_FINDSTRING is WM_USER+16)
If you want to find an exact match, the constant is:
Then put code in the text box’s lost focus event that changes the text to the selected list index. This option will mimic the operation of the search box in help files. The disadvantage is that you have that big list box on your screen all the time. (Although I guess you could toggle the visible property)

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS