Print Page | Close Window

Updating Custom Properties

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=88
Printed Date: 12-Jun-2026 at 9:59am


Topic: Updating Custom Properties
Posted By: Linguinut
Subject: Updating Custom Properties
Date Posted: 16-Jun-2007 at 11:16am

I have a set of tables in a master-detail relationship...let's call them orders and details for simplicity.  In the orders entity I have added a custom property called TotalDetails.  This iterates through the details related to the order and totals up the extended price (sum of price times quantity).  Simple enough.  Now, the details are displayed in a grid on the order form.  If I change a price or quantity in the grid, I would expect the TotalDetails property to change.  It doesn't.  The property updates if I navigate away from the order and return to it.  How do I get the custom property to update dynamically without changing entities?

Thanks!

Bill




Replies:
Posted By: jeffdoolittle
Date Posted: 18-Jun-2007 at 2:07pm
Check out the TechTip on Refreshing Dependent Parents:

http://www.ideablade.com/techtip_refreshing_dependent_parents.htm


Posted By: Linguinut
Date Posted: 18-Jun-2007 at 2:41pm
Jeff,
 
Perfect!  I added a few appropriate overrides and the form reacts beautifully.  Thanks a bunch!  The tech tip was exactly what I needed.
 
Take care,
Bill


Posted By: davidklitzke
Date Posted: 18-Jun-2007 at 2:48pm
The TechTip on "Refreshing Dependent Parents" is excellent, but I thought I would try my hand on one of the tutorials.  I started with the Fundamental tutorial on "Populating a Winform".  First, I created a custom property for TotalCost:
 

public decimal TotalCost {

      get {

        decimal total = 0;

        foreach (OrderDetail detail in this.OrderDetails) {

          total += detail.UnitPrice * detail.Quantity;

        }

        return total;

      }

    }

Then, I added an OnColumnChanging Event Handler for OrderDetail:

    protected override void OnColumnChanged(DataColumnChangeEventArgs pArgs) {

      base.OnColumnChanged(pArgs);

      this.Order.ForcePropertyChanged(null);

    }

 
I thought that this would be all I needed, but I didn't see an immediate change in TotalCost.  As a last resort, I tried adding a ForcePropertyChanged for the Employee as well:
 

protected override void OnColumnChanged(DataColumnChangeEventArgs pArgs) {

    base.OnColumnChanged(pArgs);

    this.Order.ForcePropertyChanged(null);

    PrimaryKey pKey = new PrimaryKey(typeof(Employee), this.Order.EmployeeId);

    Employee aEmployee = (Employee)this.PersistenceManager.GetEntity(pKey);

    aEmployee.ForcePropertyChanged(null);

 }
 
I am not sure why the ForcePropertChanged on Employee is necessary, but I suspect it is because this tutorial uses chained bindings.
 



Print Page | Close Window