Binding to Not Property

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 08-Dec-2006 20:01:07   

Does anyone know how to bind a control's property to the opposite (not) of a boolean data object's property? So, something like


textbox.DataBindings.Add("Visible",myEmployeeEntity,Not(IsEmployeeMarried))

In this case, I want the textbox to be visible when the myEmployeeEntity.IsEmployeeMarried is false.

Right now I have to create a property called IsEmployeeNotMarried to bind to...

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 09-Dec-2006 01:45:34   

Is it not possible to just set the textbox.Visible = !myEmployeeEntity.IsEmployeeMarried

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 09-Dec-2006 02:25:52   

bclubb wrote:

Is it not possible to just set the textbox.Visible = !myEmployeeEntity.IsEmployeeMarried

Thats pretty much what I ended up doing. But I had to catch the change events from the entity to refresh the control...something I was hoping binding would do.. disappointed

Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 09-Dec-2006 07:50:05   

Could you hook into the databinding format event and possiblying convert the result there??

Control.DataBindings[x].Format

Dont qoute me on the above, as i am going off the top of my head simple_smile

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 11-Dec-2006 21:03:33   

Answer wrote:

Could you hook into the databinding format event and possiblying convert the result there??

Control.DataBindings[x].Format

Dont qoute me on the above, as i am going off the top of my head simple_smile

Thats a good idea, I'll try that. Thanks simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Dec-2006 07:40:02   

Another idea, is to add a read-only property to the generated entity class with a getter only, to return the negation of the IsMarried property (eg. IsSingle which returns !IsMarried)

And use this new property in the databinding.