views:

245

answers:

1

I have a CheckBox that, when checked/unchecked will toggle the Enabled property of some other controls. I did have my code looking something like this:

checkBox.CheckedChanged += new EventHandler((o, e) => 
{
    control1.Enabled = checkBox.Checked;
    control2.Enabled = checkBox.Checked;
});

But today I started playing with DataBindings and discovered I could do this:

control1.DataBindings.Add("Enabled", checkBox, "Checked");
control1.DataBindings.Add("Enabled", checkBox, "Checked");

They seem to behave the same, but I suspect one is preferred over the other. Or perhaps one has some unexpected behavior that may trip me up later.

Is one way better than the other?

+2  A: 

The first one is checked at compiled time, so I'd go with that one. I assume that if the "Enabled" property in the second example was not valid you would get a runtime error.

John Buchanan
Also, you won't be able to "refactor" the second one automatically.
John Buchanan