Click here to Skip to main content
12,999,845 members (48,610 online)
Rate this:
Please Sign up or sign in to vote.
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 24-May-13 4:53am
ThePhantomUpvoter 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
    ComboBox cb = sender as ComboBox;
    if (cb != null)
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
You're welcome!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100