Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there.
I have a table of customers and a table of transactions. I use two comboboxes to get the specific transaction from a customer. I use the first cobobox to display all the customers and then by selecting the customer i want, i filter the 2nd combobox which displays the transactions to get the one i want from the selected user of the first combobox.
In the tables, each customer has its id and each transaction has its own id. Next to the transaction's id i store the id of the customer who made the transaction(to make the filtering).
I want your help in getting the id of the selected transaction of the 2nd combobox and display it to a label or a textbox.
In other words i want the instant i choose the transaction from the 2nd combobox, the value of the label to change and display the id of the selected transaction.
I use visual studio 2005 and c# and it is a windows forms project NOT ASP.NET btw.

Thnx in advance for any help guys.
Posted
Updated 1-Feb-12 22:52pm
v4
Comments
Herman<T>.Instance 2-Feb-12 4:51am    
an option: here

Jim,

For this what you have to do is, you have to bind the combo's with text and value as
C#
combo1.Item[1].text = "CustomerName";
combo1.Item[1].Value = "CustomerId"


or if you assign any datasource
then write like this
C#
combo1.DisplayMember = "CustomerName"; //Column name
combo1.ValueMember = "CustomerID"; //Column name2



Now if their is a click on combo1.

combo2.value=combo1.selectedvalue;


Thanks

SP
 
Share this answer
 
Comments
samerMarounAzar 8-May-17 17:52pm    
combo2.value does not work
You need to store all data such as some structure carrying customer information, ID, whatever else in each combo box list item. The item can an object be of any type. When you need this information, you simply cast item to you type.

The only problem is: if your combo box list items are not strings, what text will be shown in the item? The question is: whatever the method ToString returns, so you will need to override System.Object.ToString in you item type. Something like that:

C#
struct MyListItem {
   public override ToString() {
      return string.Format("{0}: {1}", this.name, this.id);
   }
   internal string Name { get { return this.name; } }
   internal int Id { get { return this.id; } }
   //...
   int id;
   string name;
   //...
}


—SA
 
Share this answer
 
Hi,
Wish you have customer ID in transaction table as forign key.
when you bind the second dropdownlist take the data and bind
C#
ValueMember 
as Tranaction ID and

C#
DisplayMember 
as Tranaction Name.

then you can select the transaction id as the way you have selected customer
id.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx[^]

hope this help.
 
Share this answer
 
v2
thanks you guys for all your quick responses!!! the first one actually worked good enough for me. i did not try the others since there was no need for me to do so but nethertheless, many thanks to all of you for your time and effort to help me.!!!
 
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