How to bind data to Control.Enabled to! (Field)?

I have a field (varchar) Foo that can only be specified if (bit) Bar is not true. I would like the textbox where Foo is displayed to be disabled when Bar is true - essentially FooBox.Enabled = !isBar

. I am trying to do something like

FooBox.DataBindings.Add(new Binding("Enabled", source, "!isBar"));

      

but of course an explosion in it raises an exception. I've also tried constructs like "isBar! = True" or "isBar <> true", but none of them work. Am I barking the wrong tree here?

+1


source to share


3 answers


I've tried to do something like this before and the best I could come up with was either

a) Changing the original class for the NotBar property and binding to it



b) Create a dumb wrapper class around the source that has a NotBar property and are bound to it.

+1


source


As far as I can tell, Databind uses reflection to find the item passed as the third row argument. You cannot pass an expression in there, just the name of the member.



+2


source


If isBar is a property of the original class (otherwise you need a property of the class to bind) this should work:

FooBox.DataBindings.Add("Enabled", source, "isBar");

      

but remember that source.isBar must exist and be boolean.

-1


source







All Articles