vendredi 10 juillet 2020

Enable/Disable specific checkbox in a specific Panel when a checkbox is checked

I'm coding a C# Forms application. I have two different Panels on my Form and I'm creating dynamic Checkboxes on both of my Panels. What I wanna do is: if I check a specific Checkbox on panel1 I want to disable/enable a specific checkbox on panel2.

foreach (Control checkbox_panel1 in checkBoxPanel1.Controls)
{
    foreach (Control checkbox_panel2 in checkBoxPanel2.Controls)
    {
        if (checkbox_panel1 is CheckBox)
        {
            CheckBox cb_p1 = (CheckBox)checkbox_panel1;
            CheckBox cb_p2 = (CheckBox)checkbox_panel2;

            if (cb_p1.Checked)
            {
                cb_p2.Enabled = false;
            }
            else
            {
                cb_p2.Enabled = true;
            }
        }
    }
}

My Code is not doing what I want. It's disabling and enabling the checkboxes in one click. And it's disabling all of the Checkboxes in Panel2 I just want one specific Checkbox to be disabled.




Aucun commentaire:

Enregistrer un commentaire