Toggling Radio Buttons In WinForms
This is what I'm doing and it results in a stack overflow because it just switches back and forth forever.
private void radioButtonA_CheckedChanged(object sender, EventArgs e)
{
radioButtonB.Checked = !radioButtonB.Checked;
}
开发者_如何学运维 private void radioButtonB_CheckedChanged(object sender, EventArgs e)
{
radioButtonA.Checked = !radioButtonA.Checked;
}
There has to be a better way to do this...
try commenting out all of your code and see if it works the way you want. you don't have to uncheck the other radio buttons in code
Is it toggling of "One" radio button what you were trying to do? If so, I tried this, and it works for me:
Set the Radio Button AutoCheck property to FALSE.
Create a "Click" event for the Radio Button.
In the Click Event Handler for the Radio Button paste the code:
radioButton.Checked = !radioButton.Checked;
I hope this helps.
You can disable the Event in the code before changing the Checked value, then add it again immediately afterwards.
精彩评论