Click here to Skip to main content
11,806,590 members (41,579 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0 C# combobox
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 at 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 at 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 at 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 at 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 at 24-May-13 11:40am
Thanx u r right...
OriginalGriff at 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
0 ppolymorphe 295
1 OriginalGriff 150
2 George Jonsson 135
3 Richard Deeming 120
4 CPallini 100
0 OriginalGriff 3,380
1 Maciej Los 1,990
2 CPallini 1,915
3 KrunalRohit 1,907
4 ppolymorphe 1,317

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2015
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