Determining radio button choice...???
-
Is there an easy way to determine which radio button in a group has been chosen, besides having to put code in the checkchanged or clicked event for each button in the group...??? thanks, vince
Like in HTML? No, unfortunately. But it doesn't have to be difficult at all. The radio buttons must be in some container, be that any given
Control
or, typically, aGroupBox
. In order for controls to show up in the UI, they must be added to the container'sControls
collection. Use that to your advantage:foreach (Control c in this.Controls)
{
RadioButton rb = c as RadioButton;
if (rb != null && rb.Checked)
{
Console.WriteLine("You selected {0}!", rb.Text);
break;
}
}-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----