The radio box is automatically checked when the program starts - but it should not be

I am writing a C # application using Visual Studio 2010. Suddenly, the strangest thing started.

I have two radio boxes at the top of the window, both set to Checked = False . I searched everywhere in the code, I see no reason why this would be anything but False .

Now the first of these two fields (called Radio1 and Radio2 respectively) began to be automatically checked at application startup. This causes a problem, because there is an event related to the cells being checked, and now this event is fired every time the program opens (which leads to serious problems).

Does anyone have any idea why this checkbox is automatically checked? As I mentioned, I searched everywhere for the code, just in case, when I chatted Radio1.Checked = true; . But this is not so.

+4
source share
3 answers

The RadioButton class contains code to ensure that at least one button in a group is checked when one of them receives focus, and the AutoCheck property is set to True. This implements standard switch behavior. If you want custom behavior, you must set your AutoCheck properties to false and run the test yourself.

+8
source

Use the counter mechanism so that for the first time you can override the click method. like this

 form_load { counter=0; } private void rb1_Click(object sender, EventArgs e) { if (counter == 0) { counter++;} else { //Do your stuff } } private void rb2_Click(object sender, EventArgs e) { if (counter == 0) { counter++;} else { //Do your stuff } } 

Hope this is helpful.

0
source

There should be no reason for this unless you set the property in the designer or through code. It’s strange.

-2
source

All Articles