Is there a more efficient way to set variables on a RadioButton's CheckChanged event?
- by C Patton
I have 16 radio buttons in an application of mine..
I have to set a variable based on which one was selected.. and I've produced some very ugly code doing this..
private void Foo_CheckedChanged(object sender, EventArgs e)
{
convertSource = 1;
}
private void Bar_CheckedChanged(object sender, EventArgs e)
{
convertSource = 2;
}
private void Baz_RadioButton_CheckedChanged(object sender, EventArgs e)
{
convertSource = 3;
}
Now, I've been thinking about it and to be honest I thought there might have been a way to do it with a switch.. I just can't conceptualize it in my mind.
If anyone could show me a more efficient way of doing this, I'd really appreciate it.
It's just really bugging me that such a simple thing as this is taking up fifty to seventy lines of code.
thanks,
cpatton