How do you set the value member of a combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have recently migrated to VS.Net 2005, and I am struggling to do something
very basic with the combo box. I want to manually loop through a data table
and add both the display text and the value manually. The reason I cannot
bind the combo box to my data table is that there are more than one field
that I want to combine to be the display member. So what I had to do was
create yet another data table at run time (or an array list) and combine the
columns in my new data table so it would display the way I want it to. This
is much more code than simply lookping through my original data table and
adding the item and setting the value manually. I don't want to have to do
this for every combo box in the application. is it possible to set the value
member of a combo box item without binding it to a data source?

I also noticed that when I set the display member to a field that has a
space in it (i.e. [last name]) the value member displays.
 
Bind to an array of objects (or fill the Combo Items collection with
objects) whose class implements a property (let's name it 'Text') which
build the display information from the various needed part of the object,
then set that property name ('Text' in our example) as the display member of
the combo.

/LM
 
Back
Top