Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am building a software in visual C# 2005 (it's my first experience). I use this code to fill a combobox:
C#
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter("Select CUSTOMER_ID,NAME from CUSTOMERS group by CUSTOMER_ID,NAME", conn);
adapter.Fill(ds);
comboBox1.DataSource = ds.Tables[0].DefaultView;
comboBox1.DisplayMember = "NAME";
comboBox1.BindingContext = this.BindingContext;

Everything is fine. The combobox is filled and only the name of the customer is shown. That's what I wanted.
But when I implement a search button, I want to put as a part of query the CUSTOMER_ID. So the combobox of the customers is clicked and after the search button is clicked I want to produce all the data that correspond to the customer name which was clicked but taking in consideration not the name that was shown in the combobox, but the customer_ID of that name.

May you help me?
Thank you
Posted
Updated 19-Oct-10 6:02am
v2
Comments
Tarun.K.S 19-Oct-10 12:37pm    
well after hitting the search button u could put the Display Member property of combobox1 to "CUSTOMER_ID".

1 solution

make the comboBox1.ValueMember = "CUSTOMER_ID".

Then, whenever a Name is selected in the comboBox, then you can use the SelectedValue property of the comboBox which will have the customer id.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900