Reputation: 27294
I have a (varchar) field Foo which can only be specified if (bit) Bar is not true. I would like the textbox in which Foo is displayed to be disabled when Bar is true -- essentially, FooBox.Enabled = !isBar
. I'm trying to do something like
FooBox.DataBindings.Add(new Binding("Enabled", source, "!isBar"));
but of course the bang in there throws an exception. I've also tried constructs like "isBar != true" or "isBar <> true", but none work. Am I barking up the wrong tree here?
Upvotes: 1
Views: 2055
Reputation: 4004
I tried doing something like this a while ago and the best I could come up with was either
a) Changing the source class to also have a NotBar property and bind to that
b) Make a dumb wrapper class around source that has a NotBar property and bind to that.
Upvotes: 1
Reputation: 12656
if isBar is a property of the source class (otherwise you need a property of a class to do the binding) this should work:
FooBox.DataBindings.Add("Enabled", source, "isBar");
but remember that source.isBar must exist and be a boolean.
Upvotes: -1
Reputation: 175653
As far as I can tell, Databind uses reflection to find the member passed as the 3rd string argument. You cannot pass an expression there, just the member name.
Upvotes: 3