hi all,
how to set the combo box so that can't simply type anything inside it to avoid error occur when vb program is executing?
Printable View
hi all,
how to set the combo box so that can't simply type anything inside it to avoid error occur when vb program is executing?
Set the Style property to 2-DropdownList
Style = 2-Dropdown List on combo1 property
when i set to style property to 2-dropdown list, the text in the combobox is combo1 and can't change anymore. i want change the text in combobox to 0. how?
At runtime it won't be combo1, but only one from the dropdown list or empty.Quote:
Originally Posted by mic_k86
If you don't want to permit blank also, just set the Combo1.ListIndex = 0 in your form_load, which will cause the first item in your dropdown list to be selected by default.
this is an example:Quote:
Originally Posted by mic_k86
Code:Private Sub Form_Load()
Dim i As Integer
For i = 0 To 9
Combo1.AddItem i
Next i
Combo1.ListIndex = 0
End Sub
When you do thisQuote:
Originally Posted by mic_k86
you lose the ability to access the text property.Quote:
Originally Posted by Pradeep1210
If you need to access the text property, but not allow any one to physically type something in the text portion of the combo, then set the style back to its default of 0 - Dropdown Combo, and do thisCode:Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
thanks everyone. my problem solved.
one question:
if i want use 0, 10, 20, 30 in my combo box, how should i change it?Quote:
For i = 0 To 9
Well,makes no sense, so we can completely discount that.Code:For i = 0 To 0
For the others, just set a variable, and use itCode:Dim x As Integer
Dim i As Integer
x = 10
For i = 0 to x
hack, wat i mean is that i just have 4 variable 0, 10, 20, 30. how to do that? however, ur reply also give me more knowledge on this case.
Won't the user be able to right click and paste something there defeating the purpose of this code? ;)Quote:
Originally Posted by Hack
Quote:
Originally Posted by mic_k86
u mean like this?
Code:For i = 0 To 30 Step 10
Combo1.AddItem i
Next i
ya. jp. is like that. one more deep question, the coding is true only for variable which hv order, if o hv few variable like 1, 5, 8, 20, 60. how to change it?
I think if you don't hve any consistancy between them, you can't just loop and add them. You will need to add them individually.Quote:
Originally Posted by mic_k86
Code:Combo1.AddItem 1
Combo1.AddItem 5
Combo1.AddItem 8
Combo1.AddItem 20
Combo1.AddItem 60
Nope...setting KeyAscii = 0 also applies to CTRL+VQuote:
Originally Posted by Pradeep1210
i agree.. heheheQuote:
Originally Posted by Pradeep1210
Errr... I meant clicking with the right mouse button and clicking Paste from the popup menu.Quote:
Originally Posted by Hack
ic. thank everyone.
I have a very simple suggestion!!!!!!!!!!!!!!!! just set the LOCKED property of the combo box to TRUE !!!!! dat will do the trick.......but i guess dat wont allow u 2 select any other option.