Search code examples
c#isenabled

C# enabling or disabling control


So, I'm losing my mind over a bug in my software.

I have this code, I use it 2 times in my software, the other function similar (with a different name) works normally. But this one is inverted...

I mean by that : Instead of enabling the controls when the groupbox.text contains "INC", it disable them.

Any idea on what is going on?

`private void Enable_disableSTM()
    {
        if (STM_groupBox.Text.Contains("INC"))
        {
            STM_radioButton_appel.Enabled = true;
            STM_radioButton_autre.Enabled = true;
            STM_radioButton_resolution.Enabled = true;
            STM_Textbox_SR.Enabled = true;
            STM_textBox_remarque.Enabled = true;
            STM_Dropdown_Sendto.Enabled = true;
            STM_pictureBox_Boutonenvoyer.Enabled = true;
        }
        else
        {
            STM_radioButton_appel.Enabled = false;
            STM_radioButton_autre.Enabled = false;
            STM_radioButton_resolution.Enabled = false;
            STM_Textbox_SR.Enabled = false;
            STM_textBox_remarque.Enabled = false;
            STM_Dropdown_Sendto.Enabled = false;
            STM_pictureBox_Boutonenvoyer.Enabled = false;
        }
    }    `

Edit :

Like I said, in my software I have this other function that is working fine. I tried also to change my IF to STM_Textbox_reademail.Text != "" and it's still not working correctly. It's inverted. Enabling when it should not and Disabling too.

`if (SQ_TextBox_reademail.Text != "")
        {
            SQ_radioButton_appel.Enabled = true;
            SQ_radioButton_autre.Enabled = true;
            SQ_radioButton_resolution.Enabled = true;
            SQ_Textbox_SR.Enabled = true;
            SQ_textBox_remarque.Enabled = true;
            SQ_Dropdown_Sendto.Enabled = true;
            SQ_pictureBox_Boutonenvoyer.Enabled = true;
        }
        else
        {
            SQ_radioButton_appel.Enabled = false;
            SQ_radioButton_autre.Enabled = false;
            SQ_radioButton_resolution.Enabled = false;
            SQ_Textbox_SR.Enabled = false;
            SQ_textBox_remarque.Enabled = false;
            SQ_Dropdown_Sendto.Enabled = false;
            SQ_pictureBox_Boutonenvoyer.Enabled = false;
        }   `

Edit 2 : Okay... I figured out something that works. I'm calling my function at a different place now and it's working. Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works! thanks all!


Solution

  • Okay... I figured out something that works. I'm calling my function at a different place now and it's working. Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works! thanks all!