Hello

I'm writing my first ever VB program. I'm using 2 combo boxes to allow the user to select 2 different pieces of information. Is there any way that I can make my program automaticaly open the first combo box up at startup so the user can easily see what they should be doing. At the moment at startup both combo boxes look like empty text boxes until the user clicks on one of them and then the box opens up. I would like to remove the need to click on the first box at startup.

Thanks you you help

Simon

Dani AI

Generated

Short summary of useful approaches already suggested in this thread: and suggested using a listbox or a default placeholder item; tried SendKeys (which often fails at startup because the form/control is not yet ready); pointed out the property that controls whether a combo is dropped. The most reliable method for opening the drop‑down on startup is to trigger the open after the form and control are actually shown and populated — below is a robust, non- SendKeys approach that works even when items are data-bound.

Imports System.Runtime.InteropServices

Public Class Form1
    Private Const CB_SHOWDROPDOWN As Integer = &H14F

    <DllImport("user32.dll", CharSet:=CharSet.Auto)>
    Private Shared Function SendMessage(hWnd As IntPtr, wMsg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function

    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        Me.BeginInvoke(Sub()
                           If ComboBox1.Items.Count > 0 Then
                               ' wParam = 1 opens, 0 closes
                               SendMessage(ComboBox1.Handle, CB_SHOWDROPDOWN, CType(1, IntPtr), IntPtr.Zero)
                           End If
                       End Sub)
    End Sub
End Class

Notes and troubleshooting: make sure the combo is populated before invoking the open (the Items.Count check avoids an empty drop). If the list is filled asynchronously or via data binding, call the open code after binding completes or from a callback once items exist. BeginInvoke (or a short timer) ensures the control handle and form are fully created so the message actually takes effect. If the form must not steal focus, prefer a visible placeholder item (as suggested) and validate that the placeholder isn’t treated as a real choice.

Accessibility and UX caveat: auto‑opening can surprise keyboard and screen‑reader users. If the goal is to draw attention, a clear placeholder label or a short animated hint is often friendlier than forcing a drop at startup.

Recommended Answers

All 11 Replies

you could use a listbox instead.

As suggested a list box would be a better option .
or
set the listindex property of the combobox to 0 (zero) so the first item in the list becomes the default choice even if user does not select anything.

you could use a listbox instead.

year i tried that but I prefer the way the Combo box looks and works to the List Box.

what bout setting the listindex to zero.

what bout setting the listindex to zero.

That works but ut would be nice to be able to have the list box pulled down so that it draws the attention of the user to the box so they know that they need to select an item from the list.

Set item 0 to "Please select an item" and the listindex to 0.

commented: Good one wayne. +4

Set item 0 to "Please select an item" and the listindex to 0.

Great Idea :-) Thanks

Simon

Hi,

Wrie this code in Got focus event of combo box:

PrivateSub ComboBox1_GotFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
SendKeys.Send("%{down}")
End Sub

This will open up the drop down list

Regards
Veena

Hi,

Wrie this code in Got focus event of combo box:

PrivateSub ComboBox1_GotFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
SendKeys.Send("%{down}")
End Sub

This will open up the drop down list

Regards
Veena

sending %{DOWN} which I think is sending Alt + the down arrow key does not seem to do anything. Lucky all the items in my selection box all start with an open bracket so by sending that it opens up the box for me. I can see why %{DOWN} should work but I cant get it to work :(

Hi,

To open the dropdown list you can use the next code:

comboBox1.DroppedDown = True

or

comboBox1.DroppedDown = false , to close

see you

Hi,

To open the dropdown list you can use the next code:

comboBox1.DroppedDown = True

or

comboBox1.DroppedDown = false , to close

see you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.