Jan,
This isn't the best way in the world to do this, but it is an option:
foreach(TabPage tp in tabControl1.Controls)
{
foreach(Control c in tp.Controls)
{
if (c is RadioButton)
{
RadioButton rb = (c as RadioButton);
if (rb.Name.EndsWith("1"))
rb.Checked = true;
}
}
}
You could check the Name or the Text property to determine which to check.
Note: The example assumes that the radio buttons are sitting on the tab
page itself. If the radio buttons are within group boxes, you will need to
interate through all the group boxes sitting on each tab page and and then
interage through group box's controls to find the radio buttons.
Hope this helps.
Dave
"Jan Smith" <JS@nospam.com> wrote in message
news:Lq******************************@giganews.com ...
I have a C# project that has a tab control with four tab pages. On each tab
page is a set of three radio buttons (named radioButton1 through
radioButton12). I would like to loop through the radio buttons and set
their state without having to form the complete name of each one, something
like this:
public static void SetButtonState(Form frm, int ButtonCount)
{
for (int i = 0; i < ButtonCount; i++)
{
frm.radioButton[i].Checked = true;
}
}
How can address each radio button without having to form its complete
name, which would require 11 extra lines of code?
Thanks for any help.