-
Hi
Just a quick question, is there any way of stopping a user typing text into a combo box, i.e. so they can only select what appears in the drop down list? I have tried using the lock propety but it does not let you select anything from the list or type anthing in.
Any takers?
Cheers
Geoff
-
You need to handle the combo box's keypress and keydown events. You can then set the keyascii and keydown values to 0 and vbnull, respectively. Let me know if you need an example.:D
-
Or better yet, just change the Style property of the Combobox to 2 (Dropdown List).
-
Thanks
Just the ticket!
Geoff
-
Some code examples would be nice on how to set it to null. I did a routine on keypress and there still is the possiblity of saving it with one character if you do it right; or is that wrong? by the user?
-
Sure. All you have to do is to set ListIndex property to -1.
Code:
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
Combo1.ListIndex = -1
End If
End Sub
Regards,
-
Combo
About how not to allow the user to input anything in a combobox
Private Sub cboBox_Change()
cboBox.Text = "" 'or whatever text
End Sub
-
No, use Combobox1_KeyPress and Combobox1_KeyUp events to do that:
Code:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
KeyCode = 0
End Sub