New Posts New Posts RSS Feed: Updating Custom Properties
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Updating Custom Properties

 Post Reply Post Reply
Author
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Topic: Updating Custom Properties
    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.
 
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jeffdoolittle View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 146
Post Options Post Options   Quote jeffdoolittle Quote  Post ReplyReply Direct Link To This Post Posted: 18-Jun-2007 at 2:07pm
Check out the TechTip on Refreshing Dependent Parents:

http://www.ideablade.com/techtip_refreshing_dependent_parents.htm
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down