Look into the DislpayMember and ValueMember in association with binding the
control to a DataSource:
This sample is in the documentation. USState being a class that has two
string properties (LongName, and ShortName):
// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each
state.
ArrayList USStates = new ArrayList();
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI"));
USStates.Add(new USState("Wyoming", "WY"));
comboBox1.SelectedValueChanged += new
EventHandler(ListBox1_SelectedValueChanged);
comboBox1.DataSource = USStates;
comboBox1.DisplayMember = "LongName";
comboBox1.ValueMember = "ShortName";
Reading the value on the changed event would look like this:
string state = (string)comboBox1.SelectedValue;
HTH,
Eric Cadwell
http://www.origincontrols.com
"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message
news:bm**********@sulawesi-fi.lerc.nasa.gov...
Is there a way to set a value for an item in a combo box that's different
than what's displayed?
So, for example, I'd like to do something like --
John Smith
Mike Jones
but hidden behind each might be an employee id (155, 239).
When user selects item on the Combo Box, I'd like to extract a hidden ID
field and use that instead of the name (which is more user-friendly to
display).
Thank you,
Laszlo