New Posts New Posts RSS Feed: Binding Enabled Property on Control to Custom Value on Entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Binding Enabled Property on Control to Custom Value on Entity

 Post Reply Post Reply
Author
vincentok View Drop Down
Newbie
Newbie
Avatar

Joined: 24-Aug-2007
Location: Ireland
Posts: 4
Post Options Post Options   Quote vincentok Quote  Post ReplyReply Direct Link To This Post Topic: Binding Enabled Property on Control to Custom Value on Entity
    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
Back to Top
Yaron View Drop Down
Newbie
Newbie


Joined: 19-Jun-2007
Posts: 16
Post Options Post Options   Quote Yaron Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
vincentok View Drop Down
Newbie
Newbie
Avatar

Joined: 24-Aug-2007
Location: Ireland
Posts: 4
Post Options Post Options   Quote vincentok Quote  Post ReplyReply Direct Link To This Post 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.


Back to Top
Yaron View Drop Down
Newbie
Newbie


Joined: 19-Jun-2007
Posts: 16
Post Options Post Options   Quote Yaron Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down