|
-
Aug 7th, 2009, 04:43 AM
#1
Thread Starter
Frenzied Member
Combobox Problem!!!
I added a few items in the combobox dropdown list at the form load event.
so i did this code:
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ComboBox1.Items.Add("Mr.")
ComboBox1.Items.Add("Mrs.")
End Sub
My form looks like this:
Attachment 72421
At the runtime I dont want to allow the user to write something in the combobox as a text.The user can only select an item from the dropdown list of the combobox.
How to do this?
Last edited by gautamshaw; Feb 21st, 2010 at 01:22 PM.
-
Aug 7th, 2009, 04:47 AM
#2
Lively Member
Re: Combobox Problem!!!
u can try this
stops them from pressing keys try this and see how it goes 4 u
Code:
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
e.SuppressKeyPress = True
End Sub
-
Aug 7th, 2009, 04:58 AM
#3
Hyperactive Member
Re: Combobox Problem!!!
You can change the style of the combobox so that it can't be edited:
Code:
' This can NOT be edited
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
'This CAN be Edited
ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
I also like to go ahead and show the first combobox element instead of leaving it blank. After I populate the box, I do this:
Code:
ComboBox1.Text = ComboBox1.Items(0)
-
Aug 7th, 2009, 05:17 AM
#4
Thread Starter
Frenzied Member
Re: Combobox Problem!!!
Hi dkahn
the below code did well:
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ComboBox1.Items.Add("Mr.")
ComboBox1.Items.Add("Mrs.")
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox1.Text = ComboBox1.Items(0)
End Sub
Now inspite of showing the 1st element of the combobox with the below code:
Code:
ComboBox1.Text = ComboBox1.Items(0)
can i leave the combobox like this so as to indicate the user that there is some items in the dropdownlist of the combo:
Attachment 72422
Last edited by gautamshaw; Feb 21st, 2010 at 01:22 PM.
-
Aug 7th, 2009, 05:46 AM
#5
Hyperactive Member
Re: Combobox Problem!!!
If you mean highlighted, but blank, you could do this:
Code:
ComboBox1.BackColor = Color.Blue
I don't see a property that highlights the empty box, but there may be one.
-
Aug 7th, 2009, 05:51 AM
#6
Thread Starter
Frenzied Member
Re: Combobox Problem!!!
well i tried this earlier....if i do this then the dropdown list of the combobox also gets colored blue.....
Is nt it possible to colour only the text box blue until an input is provided from the dropdown list?
-
Aug 7th, 2009, 06:08 AM
#7
Re: Combobox Problem!!!
Toggle the backcolor between white and blue.
-
Aug 7th, 2009, 06:11 AM
#8
Thread Starter
Frenzied Member
Re: Combobox Problem!!!
How to toggle the backcolor between white and blue?
-
Aug 7th, 2009, 07:28 AM
#9
Fanatic Member
Re: Combobox Problem!!!
VB Code:
ComboBox1.BackColor = Color.Blue ComboBox1.BackColor = Color.White
Like that. On different events
Last edited by Emcrank; Aug 7th, 2009 at 07:32 AM.
-
Aug 7th, 2009, 10:33 AM
#10
Frenzied Member
Re: Combobox Problem!!!
It would make more sense from the user standpoint to show a selection in the combo box. Even if it is < Select One > showing up. In my opinion,then you can continue on based on their selection.
-
Aug 7th, 2009, 12:10 PM
#11
Thread Starter
Frenzied Member
Re: Combobox Problem!!!
I think its a better idea to have a <Select One> Coach....
Here lies my code that i tried....
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ComboBox1.Items.Add("Mr.")
ComboBox1.Items.Add("Mrs.")
ComboBox1.Items.Add("Miss.")
ComboBox1.Items.Add("Ms.")
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
End Class
How to modify the code so that when the form loads the <Select One> option appears ?
-
Aug 7th, 2009, 01:20 PM
#12
Fanatic Member
Re: Combobox Problem!!!
Just add a Item that is called <Select One>...
-
Aug 7th, 2009, 02:11 PM
#13
Hyperactive Member
Re: Combobox Problem!!!
If i'm sure you are adding items inside it.
Easier?
-
Aug 7th, 2009, 02:55 PM
#14
Re: Combobox Problem!!!
All you need is to set the focus to the ComboBox control on the Form_Shown event handler. Alternatively you could set the Tab Order of the form where the ComboBox is the first in the list.
vb Code:
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Me.ComboBox1.Focus()
End Sub
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
|