Combo Box

G

Guest

I'm confused as to how to use the combo box in vb.net. I want a combo box to
contain items that have both a display string and a value string. The display
string gets displayed in the drop down and the value string is the key of the
item
In vb6 i could add these items to the combobox and then use
combobox.selectedvalue to set or get the selected item. How do i do this in
vb.net?
It seems I can only enter one string?
Also how do I stop users typing into the combo box? i.e. force them to
select an existing value in the dropdown and not type one in.
 
C

Cor Ligthert

Kevin,

Your first question that means that you have to create an array or what I
prefer a datatable.

Than you can set as the datasource of the combobox and use both the
displaymember and the valuemember. The last gives when selected the
selectedvalue.

Your second question means that you have to set the combobox style to
dropdownlist.

I hope this helps,

Cor
 
G

Guest

thank you. I don't really understand how to go about using an array with the
combobox, but the datatable method seems promising.
for interests sake how would u implement using an array? a multidimensional
array? what would you set the displaymember and valuemember to? with a
datatable u would use the column name but how do u reference the dimesions of
the array?

kevin
 
C

Cor Ligthert

Kevin,

You can add objects to an arraylist and use the properties of those.

I seldom did it, you have a lot to cast when you do it, I am lazy enough to
use the datatable.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top