I have a couple of RadioButtons on a C# Winforms project. I want to provide a "clear form" button which should reset the radiobuttons.
Currently I just set the RadioButton.Checked values to false and it appears to be fine.
rdbBlockRelease.Checked = false;
rdbRegularRelease.Checked = false;
The issue is when you start to tab through the form after clearing it.
Before you tab through the form, the tab order works as expected. If you check a radiobutton and then clear the form the radiobuttons appear to be removed from the taborder.
I believe this is because of how radiobuttons and tab orders work. In a radio button group, if all radio buttons are unchecked, the radio button with the lowest taborder in the group will gain focus when you tab to it.
If you check a radio button and then tab to the group, unchecked radio buttons appear to be skipped; the focus goes to the checked radio button.
Keeping this in mind, I believe what is happening the form thinks the radio button group still has a checked radio button and changing the radiobutton.checked values doesn't appear to affect that. So when the user tries to tab to the radio button group after clearing the form, the form says something like:
"Oh, okay. Give focus to the selected radio button. Oh, there's no selected radio button. Give focus to the next item in tab order."
Now comes my question. How do I prevent this? How do I make the user able to tab to the radio button group after clearing a form?
I'm using Visual Studio 2017.