By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

Get corresponding column value

P: n/a
RP
I have a combo box and I am filling Employee Codes in it. I want to
retrieve employee first and last name when a user selects an employee
code from the combo box. Though it very easy with a single SQL Query,
I want to know if there is any other way to get this. I mean if I use
following query:

Select EmpCode, FirstName, LastName from <Table Name>

and use column(o) to fill the combo box. Can I store other values as
well in combo box to retrieve them when the user selects a code.

Oct 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
bob
Hi,
You can create an employee class and fill the combo box with a set of
those.
if you overwrite the ToString() method so that it returns EmpCode then
the combox box will show that.

Use the Selected indexed changed event to get the selected item which
can be cast as an employee (if it is not already, I cant remember) and
all its properties accessed.
hth
bob

On Tue, 16 Oct 2007 08:37:57 -0000, RP <rp*********@gmail.comwrote:
>I have a combo box and I am filling Employee Codes in it. I want to
retrieve employee first and last name when a user selects an employee
code from the combo box. Though it very easy with a single SQL Query,
I want to know if there is any other way to get this. I mean if I use
following query:

Select EmpCode, FirstName, LastName from <Table Name>

and use column(o) to fill the combo box. Can I store other values as
well in combo box to retrieve them when the user selects a code.
Oct 16 '07 #2

P: n/a
Hello, RP!

If you're talking about WinForms application - combobox control has Tag
property. This property can be used to store arbitrary data.

If employee's select resultset is not large, you can cache employee data
into a data structure ( dictionary with employee code as key) and put that
data structure
into control's Tag property. When user selects value from combobox you'll
perfrom search in the attached dictionary to retrieve Emp data.

OTOH if employee's select results set can be large enough other strategies
of data retrieval have to come into play.

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Tue, 16 Oct 2007 08:37:57 -0000:

RI have a combo box and I am filling Employee Codes in it. I want to
Rretrieve employee first and last name when a user selects an employee
Rcode from the combo box. Though it very easy with a single SQL Query,
RI want to know if there is any other way to get this. I mean if I use
Rfollowing query:

RSelect EmpCode, FirstName, LastName from <Table Name>

Rand use column(o) to fill the combo box. Can I store other values as
Rwell in combo box to retrieve them when the user selects a code.

Oct 16 '07 #3

P: n/a
RP wrote:
I have a combo box and I am filling Employee Codes in it. I want to
retrieve employee first and last name when a user selects an employee
code from the combo box. Though it very easy with a single SQL Query,
I want to know if there is any other way to get this. I mean if I use
following query:

Select EmpCode, FirstName, LastName from <Table Name>

and use column(o) to fill the combo box. Can I store other values as
well in combo box to retrieve them when the user selects a code.
Yes you can. If it's databound it's pretty easy:

comboBox1.DataSource = dt;
comboBox1.DisplayMember = "EmpCode";
comboBox1.ValueMember = "EmpCode";

Then you can extract the DataRow/DataRowView (by default if you bind it,
it's a DataRowView) from the combobox like:

DataRowView row = (DataRowView)comboBox1.SelectedItem;
MessageBox.Show(row["EmpCode"].ToString() + ": " +
row["FirstName"].ToString() + " " +
row["LastName"].ToString());

If it's your own custom object, it's pretty much the same. SelectedItem
would be whatever you added via a data binding process or via the
comboBox1.Items.Add() method.
Chris.
Oct 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.