|
-
Dec 19th, 2008, 03:40 AM
#1
Thread Starter
Addicted Member
[RESOLVED] dont want any typing on combo box
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?
-
Dec 19th, 2008, 03:42 AM
#2
Re: dont want any typing on combo box
Set the Style property to 2-DropdownList
-
Dec 19th, 2008, 03:44 AM
#3
-
Dec 19th, 2008, 07:59 AM
#4
Thread Starter
Addicted Member
Re: dont want any typing on combo box
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?
-
Dec 19th, 2008, 08:31 AM
#5
Re: dont want any typing on combo box
 Originally Posted by mic_k86
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.
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.
-
Dec 19th, 2008, 08:34 AM
#6
Hyperactive Member
Re: dont want any typing on combo box
 Originally Posted by mic_k86
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?
this is an example:
Code:
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 9
Combo1.AddItem i
Next i
Combo1.ListIndex = 0
End Sub
"More Heads are Better than One"
-
Dec 19th, 2008, 08:52 AM
#7
Re: dont want any typing on combo box
 Originally Posted by mic_k86
i want change the text in combobox
When you do this
 Originally Posted by Pradeep1210
Set the Style property to 2-DropdownList
you lose the ability to access the text property.
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 this
Code:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
-
Dec 19th, 2008, 08:57 AM
#8
Thread Starter
Addicted Member
Re: dont want any typing on combo box
thanks everyone. my problem solved.
one question:
if i want use 0, 10, 20, 30 in my combo box, how should i change it?
-
Dec 19th, 2008, 09:02 AM
#9
Re: dont want any typing on combo box
Well, makes no sense, so we can completely discount that.
For the others, just set a variable, and use it
Code:
Dim x As Integer
Dim i As Integer
x = 10
For i = 0 to x
-
Dec 19th, 2008, 09:08 AM
#10
Thread Starter
Addicted Member
Re: dont want any typing on combo box
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.
-
Dec 19th, 2008, 09:10 AM
#11
Re: dont want any typing on combo box
 Originally Posted by Hack
When you do this
you lose the ability to access the text property.
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 this
Code:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Won't the user be able to right click and paste something there defeating the purpose of this code?
-
Dec 19th, 2008, 09:14 AM
#12
Hyperactive Member
Re: dont want any typing on combo box
 Originally Posted by mic_k86
thanks everyone. my problem solved.
one question:
if i want use 0, 10, 20, 30 in my combo box, how should i change it?
u mean like this?
Code:
For i = 0 To 30 Step 10
Combo1.AddItem i
Next i
"More Heads are Better than One"
-
Dec 19th, 2008, 09:27 AM
#13
Thread Starter
Addicted Member
Re: dont want any typing on combo box
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?
-
Dec 19th, 2008, 09:45 AM
#14
Re: dont want any typing on combo box
 Originally Posted by mic_k86
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.
Code:
Combo1.AddItem 1
Combo1.AddItem 5
Combo1.AddItem 8
Combo1.AddItem 20
Combo1.AddItem 60
-
Dec 19th, 2008, 09:46 AM
#15
Re: dont want any typing on combo box
 Originally Posted by Pradeep1210
Won't the user be able to right click and paste something there defeating the purpose of this code? 
Nope...setting KeyAscii = 0 also applies to CTRL+V
-
Dec 19th, 2008, 09:49 AM
#16
Hyperactive Member
Re: dont want any typing on combo box
 Originally Posted by Pradeep1210
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.
Code:
Combo1.AddItem 1
Combo1.AddItem 5
Combo1.AddItem 8
Combo1.AddItem 20
Combo1.AddItem 60
i agree.. hehehe
"More Heads are Better than One"
-
Dec 19th, 2008, 09:58 AM
#17
Re: dont want any typing on combo box
 Originally Posted by Hack
Nope...setting KeyAscii = 0 also applies to CTRL+V
Errr... I meant clicking with the right mouse button and clicking Paste from the popup menu.
-
Dec 20th, 2008, 01:55 AM
#18
Thread Starter
Addicted Member
Re: dont want any typing on combo box
-
Dec 26th, 2008, 03:58 AM
#19
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|