ComboBox Values

Morn

Active member
Joined
Dec 4, 2006
Messages
40
Programming Experience
Beginner
Finaly I get to ask a simple question.

I have some ComboBoxes and I want to do two things with them:

1) Make there be a value in it rather than blank then the form loads (it is populated by the properties tab rather than in the code)

2)Not allow anything other than the values in the list to be used (i.e. make it uneditable)

Any ideas?

Thanks Graham
 
2)Not allow anything other than the values in the list to be used
(i.e. make it uneditable)
u can try this
in the combobox keypressed event write
e.handled=true
 
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2][COLOR=#008000]'Add values to your combo box, but you can bind your combobox to a datasource[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ComboBox1.Items.AddRange([/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2]() {[/SIZE][SIZE=2][COLOR=#a31515]"One"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"Two"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"Three"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"Four"[/COLOR][/SIZE][SIZE=2]})[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList [/SIZE][SIZE=2][COLOR=#008000]'Set to drop down (readonly)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ComboBox1.SelectedIndex = 0 [/SIZE][SIZE=2][COLOR=#008000]'Select first item[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
Back
Top