views:

35

answers:

2

I have a checkbox with a Checked property and a Listbox with an Enabled property. I'd like to data bind the controls in such a manner that when the user checks the Checkbox, the listbox becomes enabled. Conversely, when the user unchecks the checkbox, the listbox becomes disabled.

How can I do something like that?

A: 

Is this what you need?

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                listBox1.Enabled = true;
            }
            else
            {
                listBox1.Enabled = false;
            }
        }
Raymund
or even `listBox1.Enabled = checkBox1.Checked;`
Jon
No. I don't want to muck up the form with code like this. I am doing it via DataBinding.
AngryHacker
+1  A: 

Sorry, I should have done a bit of googling. The answer is actually pretty simple:

cbo.DataBindings.Add("Enabled", chk, "Checked");
AngryHacker