Databinding to boolean property, but need opposite valueDatabinding to boolean property, but need opposite value
Old forum URL: forums.lhotka.net/forums/t/3686.aspx
xxxJasonxxx posted on Wednesday, October 10, 2007
I'm binding a textbox's "ReadOnly" property to the boolean property on one of my business objects. However I need the "ReadOnly" property to be the OPPOSITE of the business object's property. I'd rather not change the business object's property to use the opposite value and different name because of the way this value is used in our business (it would be confusing to other people). Is there some way to format this binding to switch the boolean to the opposite value? Like the equivalent of using a "Not" keyword somehow inside the "TextBox1.DataBinding.Add(xxxxx)" statement to flip the value. Anybody got any ideas?
Jason
ajj3085 replied on Wednesday, October 10, 2007
I think if you find the Binding object you can use either the Format or Parse events to perform the flip. Get the binding from the controls DataBindings collection.
xxxJasonxxx replied on Thursday, October 11, 2007
I played around with various properties/methods on the Databindings collection items...
TextBox1.DataBindings.Item(0).xxxxx
I didn't see "Format" or "Parse" - the closest thing was "FormatString".
I didn't have any luck with any of the properties/methods I tried.
Jason
ajj3085 replied on Thursday, October 11, 2007
Format and Parse are events that you listen to. See ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref17/html/T_System_Windows_Forms_Binding_Members.htm#PublicEventsToggle
Andy
xxxJasonxxx replied on Thursday, October 11, 2007
Got it...
Dim objBinding As New Binding("ReadOnly", mobjOrder.FeesTaxesTotals, "BrokerageFeeIsOverridden")
AddHandler objBinding.Format, AddressOf BrokerageBindingFormat
txtBrokerage.DataBindings.Add(objBinding)
I switch the value inside the "BrokerageBindingFormat" handler sub.
Thanks for your help Andy.
Jason
Copyright (c) Marimer LLC