Reputation: 51
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!
Upvotes: 3
Views: 4894
Reputation: 1
Use this in a Private Sub ComboBox1_Change()
event. This just selects the active cell, which would be whatever cell you placed your ComboBox in.
Private Sub TempCombo_Change()
If TempCombo.ListIndex > -1 Then
'MsgBox ("Done") ' Item is selected
ActiveCell.Select
End If
End Sub
Upvotes: 0
Reputation: 9888
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.
Upvotes: 4