Forcing List to Drop

Forcing List to Drop

Question:
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?

Answer:
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:

Const WM_USER = &H400Const CB_FINDSTRING = (WM_USER + 12)Const CB_FINDSTRINGEXACT = (WM_USER + 24)Const CB_SHOWDROPDOWN = (WM_USER + 15)Const CB_GETDROPPEDSTATE = (WM_USER + 23)
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:
LB_FINDSTRINGEXACT (WM_USER+35)
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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes