Hi all, I have a save button that should be disabled unless the checkbox is 'checked' the code I have makes no difference even though I think it should! Any help is appriciated.

private void EnabledCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var checkbox = (CheckBox)sender;
            foreach (Control c in this.Controls)
            {
                if (checkbox.Checked)
                    SaveButton.Enabled = true;
                else
                    SaveButton.Enabled = false;
            }


        }

The foreach loop is unecessary, take it out and it should work.

You don't even need the if statement

private void EnabledCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var checkbox = (CheckBox)sender;
            SaveButton.Enabled = checkbox.Checked;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.