Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 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 5:53am
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

Try:
private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
    ComboBox cb = sender as ComboBox;
    if (cb != null)
        {
        ...
        }
    }
  Permalink  
Comments
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
   
:laugh:
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 OriginalGriff 341
1 Marcin Kozub 225
2 Praneet Nadkar 197
3 Sergey Alexandrovich Kryukov 190
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


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