vb.netcombobox

How can you cause a combobox to loose focus?


I am developing a windows forms project in vb.net. I have added a comboBox to my form. the form automatically focuses on the comboBox. Nothing I click on causes the comboBox to loose focus. I do not want the form to focus on the comboBox because I do not want users to change the selected text in the comboBox by accidentally moving the scroll wheel.

I have tried:

comboBox1.CanFocus = False 
comboBox1.Focus = false 

These properties are not write-able.

InvokeLostFocus(ComboBox1, New EventArgs)

This does not throw a compiler error but it does not seem to do anything either (focus stays).

I am really stuck and can not find anything on SE or google. Any help is much appreciated.

Thanks!


Solution

  • You need to focus another control. Note that the form itself cannot be focused.

    Something like:

    label1.Focus()
    

    If this doesn't work for you, you can try this:

    Private Sub Form1_Load(sender As Object, e As EventArgs)  
        Me.ActiveControl = label1;       
    End Sub
    

    You can even try to disable and enable the ComboBox.