Multiple Radio buttons In A Form
-
I have 50 radio buttons in a form. can i use a loop to check which radio button is checked ? :zzz:
-
I have 50 radio buttons in a form. can i use a loop to check which radio button is checked ? :zzz:
-
I have 50 radio buttons in a form. can i use a loop to check which radio button is checked ? :zzz:
Ravindra Bisen wrote:
50 radio buttons in a form
Why? If you've got this many options, maybe a dropdown combo or a list would be a better idea? With either if these finding the selected item is easy. Alternatively if you absolutly must have all the radio buttons, on the CheckedChange event catch the pressed button as it will be the object sender.
Panic, Chaos, Destruction. My work here is done.
-
I have 50 radio buttons in a form. can i use a loop to check which radio button is checked ? :zzz:
The alternative is to have a class member
RadioButton LastChecked
and to give all RadioButtons the same CheckedChanged handler, which simply updatesLastChecked=(RadioButton)sender;
for the last one whose Checked property became true. :) -
The alternative is to have a class member
RadioButton LastChecked
and to give all RadioButtons the same CheckedChanged handler, which simply updatesLastChecked=(RadioButton)sender;
for the last one whose Checked property became true. :) -
Yup. You'd typical loop through the
Control
-collection of the form, checking if theControl **is**
aradioButton
, and if it is, downcast it to aRadioButton
and read the value. --edit-- Forgot to close one of the <code> tagsI are troll :)
hi i am using like this.. opt_no=1;score=0; foreach (Control rd in this.Controls) { string rdo= "radioButton"+opt_no"; if (rd.Name == rdo && rd is RadioButton) { // my code is here rd.Checked=true; // the line gives an error } opt_no= opt_no+1; } it takes only that control which is designed into form. but i designed all radio buttons into flowLayoutPanel. i have 100 question and each Que. has four option(means four Radio button which is created in a panel).i am checking score. i am taking question no and ans from a table.
-
I have 50 radio buttons in a form. can i use a loop to check which radio button is checked ? :zzz:
as williamnw pointed out, try to chnage you design. 50 radio buttons is way too much. It can be replaced with drop down or list control.
Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
-
hi i am using like this.. opt_no=1;score=0; foreach (Control rd in this.Controls) { string rdo= "radioButton"+opt_no"; if (rd.Name == rdo && rd is RadioButton) { // my code is here rd.Checked=true; // the line gives an error } opt_no= opt_no+1; } it takes only that control which is designed into form. but i designed all radio buttons into flowLayoutPanel. i have 100 question and each Que. has four option(means four Radio button which is created in a panel).i am checking score. i am taking question no and ans from a table.