I have lot of dynamically generated radio buttons in my Windows Forms project. They may be checked based on the values in a database. I want to clear all radio buttons in a
void Button1Click(object sender, EventArgs e)
{
foreach (Control ctrl in Controls)
{
if (ctrl is Panel)
{
foreach (Control rdb in ctrl.Controls)
{
if (rdb is RadioButton && ((RadioButton)rdb).Checked == true)
{
((RadioButton)rdb).Checked = false;
}
}
}
}
}
This clears all the checked radio buttons on a button click.