PDA

Click to See Complete Forum and Search --> : Looping through controls


birthjay
Feb 11th, 2005, 01:24 PM
Hello,

I have this code that works for checking just one RadioButton to see if it is checked when looping through a group of RadioButtons. How can I check ALL of the RadioButtons?


foreach(Control EnumControl in this.Frame1.Controls)
{
if (EnumControl.GetType().Equals(typeof(RadioButton)))
{
if (optCommand0.Checked == true) //What do I do here to check ALL RadioButtons?
{
MessageBox.Show("I'm Here");
break;
}
}
}

crptcblade
Feb 11th, 2005, 01:30 PM
foreach(Control EnumControl in this.Frame1.Controls)
{
if (EnumControl.GetType().Equals(typeof(RadioButton)))
{
if (optCommand0.Checked == true)
{
MessageBox.Show("I'm Here");
break;
}
}
}

birthjay
Feb 11th, 2005, 01:37 PM
My RadioButtons are:

optCommand0
optCommand1
optCommand2.
etc...

In other words, I have many and would like to know how to loop through them without having to list each one. Sort of like optCommand(i).checked .

birthjay
Feb 11th, 2005, 03:16 PM
//Loops through controls in a Frame. Finds "checked" RadioButton and displays it's name.


foreach(Control ctrl in Frame1.Controls)
{
if(ctrl.GetType() == typeof(RadioButton))
{
if(((RadioButton)ctrl).Checked == true)
{
MessageBox.Show(ctrl.name);
}
}
}