Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 84 combo box inside 12 group box, in a group of 12. Combo Box are named as cb1,cb2,cb3,cb4,cb5,cb6,...... Group Box are named as gBox1,gBox2,gBox3,gBox4,gBox5,.... Now I want to save the item name in a variable when I select or change item of any combo box. I know that if I use SelectedIndexChanged for each combo box then I can get what I want, I am wondering that is the only way to do.... OR there is any simplified way to achieve the above mentioned purpose.

I welcome any suggestion/advice/guidance.

Regards to all
Posted
Comments
[no name] 24-May-13 10:57am    
"84 combo box", you have design issue not a combobox issue
"SelectedIndexChanged for each combo box", why don't you use the same event handler for all of the comboboxes?
vishal deb 24-May-13 11:10am    
Thank you for suggestion but can you please give some small hint on code how to use same event handler for all of the comboboxes

1 solution

Try:
C#
private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
    ComboBox cb = sender as ComboBox;
    if (cb != null)
        {
        ...
        }
    }
 
Share this answer
 
Comments
vishal deb 24-May-13 11:08am    
Thank you for your guidance.. But I am bit confused about your code. What does myComboBox represent in your code. If it the name of one of the combo box out of 84 combo boxes then how the problem is solved?
OriginalGriff 24-May-13 11:12am    
No, you point all of the comboboxes at the same event handler method.
When the event fires, the same handler routine is called, with the ComboBox that had the selection change passed through as the sender parameter.
The code converts the sender to a ComboBox, and you can then use "cb" as if it was the name of the ComboBox on your form.

Try it! You'll see what I mean...
vishal deb 24-May-13 11:40am    
Thanx u r right...
OriginalGriff 24-May-13 12:12pm    
:laugh:
You're welcome!

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