Re-Binding necessary for Readonly BO properties?

Re-Binding necessary for Readonly BO properties?

Old forum URL: forums.lhotka.net/forums/t/938.aspx


marioe2000 posted on Thursday, August 17, 2006

I have a BusinessBase descendant that is composed of a few string properties as well as a single ReadOnlyBase object.

Simplified version:

Public Class ROZipCode
  Inherits ReadOnlyBase

  private _ZipCode as string
  private _County as string
  private _State as string
 
  public readonly property ZipCode as string …
  public readonly property CountyName as string …
  public readonly property StateName as string …

...

End Class

Public Class Location
  Inherits BusinessBase

  private _LocName as string
  private _LocDescription as string
  private _LocZIP as ROZipCode

  public property LocName as string ...
  public property LocDescription as string
  public property LocZIP as ROZipCode
‘  ... get/set methods (CheckRules & MarkDirty called on set) for all properties
‘ … DataAccess/ Shared Methods and the rest needed

End Class 

Public Class EditLocationForm
  Inherits System.Windows.Forms.Form

 

Public Sub BindFields()

  ‘BindField for each Location property including LocZIP binded to a ButtonEdit ‘descendant that returns an ROZipCode.

  ‘ I’m also binding LocZIP properties to readonly text boxes for display purposes.
  BindField(CheckBox1, “Checked”, SomeLocation, “IsDirty”)
  BindField(TextBox1, “Text”, SomeLocation, “LocName”)
  BindField(CustomLookupEdit1, “Text”, SomeLocation, “LocZIP”) 'Bound to a ROZipCode object
  BindField(TextBox11, “Text”, SomeLocation.LocZIP, “CountyName”)
  BindField(TextBox12, “Text”, SomeLocation.LocZIP, “StateName”)

End sub

 

The CustomLookupEdit control is a descendant of a devexpress ButtonEdit control which through the Format/Parse mechanism “converts” a ROZipCode to text and back again; it also does some lookup and search functions. In the end it returns a ROZipCode to it’s bound property. This I know is working fine because the LocZIP property of SomeLocation changes accordingly whenever the custom control looks up a different zip code.

The problem is that although it’s value changes correctly within the Location instance, the textboxes to which the LocZIP properties are bound to (TextBox11, TextBox12) don’t get refreshed.

 

Why is this? At first I had forgatten to bind the checkbox to SomeLocation.IsDirty, but I’ve since corrected that and still no-go.

 

I’ve done my fair share of research on both searchcsla.com and this forum to no‑avail.

 

Can some one point me in the right direction, I’m sure the answer to this is lurking somewhere but I Still Haven’t Found What I’m Looking For …

 


Thanks

 

Mario Estrella

 

marioe2000 replied on Friday, August 18, 2006

The solution I'm using right now is trapping the Validated event for the custom lookup control from the EditLocationForm and do a re-bind. This works fine, but I dont think I should have to do it.

Is there a better approach to this?

Thanks

ajj3085 replied on Friday, August 18, 2006

The problem is that the RO object doesn't support the IPropertyChanged interface, and doesn't raise PropertyChanged events when the RO properties are updated.  You'll have to manually implement this interface and raise the events to update the display.

HTH
Andy

xal replied on Friday, August 18, 2006

I didn't read all the discussion, so forgive me if I'm off the subject...
But if you have a readonly property that changes based on others, you could override on property changed like:

Protected Overrides Sub OnPropertyChanged(propertyName as string)
If propertyName = "PropA" Or propertyName = "PropB" Then
PropertyHasChanged ("TheReadOnlyProp")
End If
End Sub



Andrés

Brian Criswell replied on Friday, August 18, 2006

xal:
I didn't read all the discussion, so forgive me if I'm off the subject...
But if you have a readonly property that changes based on others, you could override on property changed like:

Protected Overrides Sub OnPropertyChanged(propertyName as string)
If propertyName = "PropA" Or propertyName = "PropB" Then
PropertyHasChanged ("TheReadOnlyProp")
End If
End Sub
Andrés

Is that necessary?  I thought I remembered Rocky mentioning that DataBinding automatically refreshes all properties aside from the one that caused the update, hence the need for the BindingRefresh component.

marioe2000 replied on Friday, August 18, 2006

I'm still using CSLA 1.5 ... doing a little research it seems the IPropertyChanged interface is for CSLA 2.0 or at least .NET 2.

Am I correct? if so, is there something similar for CSLA 1.5?

xal replied on Friday, August 18, 2006

Well, in that case, the same thing <should> apply if you call PropertyChange() passing the new info...
You might have to bind something to isvalid / isdirty for that to work...

Andrés

Copyright (c) Marimer LLC