New Posts New Posts RSS Feed: Computed fields not updating in UI
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Computed fields not updating in UI

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

Joined: 26-Jul-2011
Location: Minneapolis
Posts: 11
Post Options Post Options   Quote Togas Quote  Post ReplyReply Direct Link To This Post Topic: Computed fields not updating in UI
    Posted: 08-Aug-2011 at 11:31am
I added a field to my entity to show the total of 3 fields.



Public ReadOnly Property TotalMonthlyPayment()
	Return MonthlyPayment.GetValueOrDefault + OptionPayment.GetValueOrDefault + UpgradeAmount.GetValueOrDefault
End Sub

If I changed one of the 3 values in my UI the total field is not updated.  I found this article and it seems like it should be.
http://www.ideablade.com/DevForceClassic/TechTips/techtip_refreshing_dependent_parents.htm
Specifically here:
"The answer depends upon whether the independent property that got changed lives in the same object, or an external one. Suppose, for example, that you have an Employee class that defines a (computed) Age property whose values depends upon the Employee’s (persistable) BirthDate (as illustrated in many of our Fundamentals tutorials). If a user changes the BirthDate value, PropertyChanged will fire on the Employee instance. Data bindings to that Employee in a form or UserControl listen for this event, and they will notify their controls when it occurs. All the data bindings for the Employee instance will get updated, so the Age value will be updated to correspond to the new BirthDate."

If I'm reading this right I shouldn't need to do anything for my computed value to update but that's not what I'm seeing.



I did write this and it works but it seems like a lot of work for simple calculated fields, am I missing something?

Partial Public Class Order
  Inherits ibem.entity


  Private _TotalMonthlyPayment As Decimal
  Private TotalInit As Boolean = False


  <AfterSet(EntityPropertyNames.MonthlyPayment)> _
  <AfterSet(EntityPropertyNames.OptionPayment)> _
  <AfterSet(EntityPropertyNames.UpgradeAmount)> _
  Public Sub FireTotalMonthlyPaymentChanged(ByVal args As PropertyInterceptorArgs(Of Order[String])) 
    CalulateTotalMonthlyPayment()
    OnPropertyChanged(New PropertyChangedEventArgs("TotalMonthlyPayment"))
  End Sub

  Public Sub CalulateTotalMonthlyPayment()
    _TotalMonthlyPayment = MonthlyPayment.GetValueOrDefault + OptionPayment.GetValueOrDefault + UpgradeAmount.GetValueOrDefault
  End Sub

  Public ReadOnly Property TotalMonthlyPayment() As Decimal
    Get
      If TotalInit Then
        Return _TotalMonthlyPayment
      Else
        CalulateTotalMonthlyPayment()
        Return _TotalMonthlyPayment
      End If
    End Get
  End Property


Edited by Togas - 09-Aug-2011 at 6:36am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 09-Aug-2011 at 5:53pm
Hi Togas,
 
You will need to raise PropertyChanged when any of the 3 property values is updated.
 
However, you don't need to call a method to calculate it each time assuming your calculated property getter already does so.
 
 
Partial Public Class Order
  Inherits ibem.entity 

  Private _TotalMonthlyPayment As Decimal
  Private TotalInit As Boolean = False 

  <AfterSet(EntityPropertyNames.MonthlyPayment)> _
  <AfterSet(EntityPropertyNames.OptionPayment)> _
  <AfterSet(EntityPropertyNames.UpgradeAmount)> _
  Public Sub FireTotalMonthlyPaymentChanged(ByVal args As PropertyInterceptorArgs(Of Order, [String])) 
    OnPropertyChanged(New PropertyChangedEventArgs("TotalMonthlyPayment"))
  End Sub
 
  Public ReadOnly Property TotalMonthlyPayment() As Decimal
    Get
      Return MonthlyPayment.GetValueOrDefault + OptionPayment.GetValueOrDefault + UpgradeAmount.GetValueOrDefault
    End Get
  End Property
 
Regards,
   Silvio.
Back to Top
Togas View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Jul-2011
Location: Minneapolis
Posts: 11
Post Options Post Options   Quote Togas Quote  Post ReplyReply Direct Link To This Post Posted: 10-Aug-2011 at 6:59am
Much cleaner, thank Silvio!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down