Help with Collections
-
Greetings! I have a set of 6 RadioButtons, one of which is set based on a user-selection in a ListBox on the same form. What I want to do is to disable the other 5 RadioButtons after the user makes the selection and one RadioButton is set. I'm assuming that a collection is the best way to do this, so I can write some code that disables every RadioButton that is not the one that is selected. Could you help me define this Collection? I've looked through MSDN and pages online but I'm a little confused about how one defines a collection. Thanks!
-
Greetings! I have a set of 6 RadioButtons, one of which is set based on a user-selection in a ListBox on the same form. What I want to do is to disable the other 5 RadioButtons after the user makes the selection and one RadioButton is set. I'm assuming that a collection is the best way to do this, so I can write some code that disables every RadioButton that is not the one that is selected. Could you help me define this Collection? I've looked through MSDN and pages online but I'm a little confused about how one defines a collection. Thanks!
In page_load or where you initialize your variables do:
List<RadioButton> buttons = new List<RadioButton>();
buttons.Add(RadioButton1);
buttons.Add(RadioButton2);
buttons.Add(RadioButton3);
buttons.Add(RadioButton4);
buttons.Add(RadioButton5);
buttons.Add(RadioButton6);Then you can iterate throug them with loops:
foreach (RadioButton rb in buttons)
{
if(!rb.Checked)
rb.Enabled = false;
} -
In page_load or where you initialize your variables do:
List<RadioButton> buttons = new List<RadioButton>();
buttons.Add(RadioButton1);
buttons.Add(RadioButton2);
buttons.Add(RadioButton3);
buttons.Add(RadioButton4);
buttons.Add(RadioButton5);
buttons.Add(RadioButton6);Then you can iterate throug them with loops:
foreach (RadioButton rb in buttons)
{
if(!rb.Checked)
rb.Enabled = false;
}...