Quick question, I know there is a foreach
statement that checks each specified control in a form, but is there a forany
statement that can check for a specific control amongst a group of the same types of controls, or is there a certain specification I can use in a foreach
state that limits it. For example: Say I check if ANY RadioButton on a form is checked. If one is checked, it a message box will display "Hi". My approach would go something like:
foreach (Control rb in this.Controls.OfType<RadioButton>())
{
if(((RadioButton(rb)).Checked == true)
{
MessageBox.Show("Hi");
return;
}
}
The problem with this is it checks ALL RadioButtons and sees if they are checked. I don't want that. I want it to check if anyone of the are checked. Is there a way I can manipulate this?