473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

combo box -- dumb question

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
Nov 15 '05 #1
2 1249
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

Nov 15 '05 #2
Thank you very much.

Laszlo
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
4
by: vermon | last post by:
This question is pretty dumb, but I am wondering what do you people prefer to use for a conceptual "yes/no" field: a combo box or radio buttons? My goal is the simplest possible to read GUI with...
7
by: JimReid | last post by:
I have created combo boxes in the past in access but for some reason now it doesn't seem to work. I drag the combo on the screen and hook it up with a query. When I execute the process and see the...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.