Is there a more efficient way to set variables on a RadioButton's CheckChanged event?
Posted
by C Patton
on Stack Overflow
See other posts from Stack Overflow
or by C Patton
Published on 2010-03-30T01:47:29Z
Indexed on
2010/03/30
1:53 UTC
Read the original article
Hit count: 336
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
© Stack Overflow or respective owner