I’ve got an event handler that is shared by all of my radiobuttons:
private void radioButtonPackers_CheckedChanged(object sender, EventArgs e)
{
var rb = sender as RadioButton;
if (rb == radioButtonPackers)
{
team = NFCNorth.Packers;
} else if (rb == radioButtonBears)
{
team = NFCNorth.Bears;
} else if . . .
}
rb is always seen as being radioButtonPackers, even after I’ve checked the radioButtonBears, radioButtonVikings, or radioButtonLions radiobutton.
Do I have to do something like:
if (radioButtonPackers.Checked)
{
team = NFCNorth.Packers;
}
else if (radioButtonBears.Checked)
{
team = NFCNorth.Bears;
}
. . .
?
You need to take note of
rb.Checked, but in my experience you’ll get an “unchecked” event before you get the “checked” one anyway. Here’s a short but complete example which works:If you click on Button 1 then on Button 2, you’ll see: