I have these groupboxes:
I want to run some code according to checked true state of a radio button like:
string chk = radiobutton.nme; // Name of radio button whose checked is true
switch(chk)
{
case "Option1":
// Some code
break;
case "Option2":
// Some code
break;
case "Option3":
// Some code
break;
}
Is there any direct way so that I can only get the name of the checked radio button?
You can find all checked RadioButtons like
var buttons = this.Controls.OfType<RadioButton>()
.FirstOrDefault(n => n.Checked);
Also take a look at CheckedChanged
event.
Occurs when the value of the Checked property changes.