Print Page | Close Window

Binding Enabled Property on Control to Custom Value on Entity

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=522
Printed Date: 13-Apr-2026 at 8:07am


Topic: Binding Enabled Property on Control to Custom Value on Entity
Posted By: vincentok
Subject: Binding Enabled Property on Control to Custom Value on Entity
Date Posted: 24-Oct-2007 at 6:56am
Folks,

I have a situation where I need to bind the enabledness of a number of controls on a form to a custom value on an entity.

Every time I update a control, I run an UpdateState method on my base entity to set these custom properties to true or false.

I've added windows databinding to achieve this, as per the Developer Manual, at page 328

            EmployerTypeComboBox.DataBindings.Add("Enabled", serviceHistoryAddUpdatePanelManager.BindingSource, "EmployerTypeEnabled", false, DataSourceUpdateMode.OnPropertyChanged);

But, the behaviour of the control is that it will only set its enabledness after it's been validated a second time.

Is there a better way to achieve this using ControlBindingManager?

TIA



Replies:
Posted By: Yaron
Date Posted: 24-Oct-2007 at 6:53pm
I have been using this method plenty, I typically bind it to a ReadOnly property. this property will update itself when ever a property is changed (managed by the framework) just make sure that your Get method does the job


Posted By: vincentok
Date Posted: 25-Oct-2007 at 5:10am
That's great, Yaron, but I'm afraid it doesn't actually work for me.

I'm calling the UpdateState method after having validated a control that is also bound to a ControlBindingManager.

For some reason, I have to try setting the value on the control again, so the validated event and, susequently UpdateState method gets called a second time, in order for the winforms databiding to reflect the changes to the property.

I tried calling the UpdateState method twice in a row which is not only inherently repugnant from a coding perspective but also results in odd or inconsistent behaviour.

There's no problem with the get method since it's only returning true or false based on conditions I set in the UpdateState method.

How / when / where do you set up these databindings?

What seems to be happening is that the Winforms binding doesn't pick up that a change has occurred or picks up that a change has occurred before the control is validated and before the enabled properties of the dependent controls have been set to false.

In general, I'm curious to know the life cycle of events that occur between changing a value on a control, it being validated, the controlbindingmanager picking up on it, windows binding picking up on it and how subsequent entity property changes impact.

But, for now, any ideas on the mechanics of getting this working would be great.




Posted By: Yaron
Date Posted: 25-Oct-2007 at 6:31am
From your initial description of the problem, sounds like you are using the AfterPropertyChanged event,
I am not the expert, but for what I can remember, the change of a property value causes the UI to envalidate (repaint) and recall all the Get methods of the entity's properties. I normally use something like this:
 
Public ReadOnly Property EnabledState() as Boolean
   Get
         Return GetCanEnable
   end Get
End Property
 
Private function GetCanEnable() as Boolean
 do some if....
 
End Function
 
If this doesn't help, maybe you can post your code example



Print Page | Close Window