Greying out a checkbox when another is checked

c#

Solution

Listen to the first CheckBox's CheckedChanged event with a method like this one:

private void checkBox1_checkedChanged(object sender, EventArgs e)
{
    this.checkBox2.Enabled = !this.checkBox1.Checked;

    // If you want it to be unchecked as well as grayed out,
    // then have this code as well:
    if (!this.checkBox2.Enabled)
    {
        this.checkBox2.Checked = false;
    }
}

But you should consider using RadioButtons instead of CheckBoxes, if it logically fits to your needs.

Problem

Basically, I have a list of delivery checkboxes one for deliver to this address and another for deliver to a separate address, I basically want to make it so once one has been checked the other can not be checked out (perhaps by greying it out or something along those lines) Please be aware that both boxes use the same controls.

Original source