In order for WinForms databinding to refresh the parent "sum" I suppose you could attach a handler in the parent object to the listchanged event of the list of children - capture deletes and itemchanged for the weight property and then do as you say - fire the property changed for the parent's property (which I assume sums up the child weights).
The insert case probably doesn't matter since I imagine their default value is 0 or null.
Chris
I don't have real knowledge of your use case here, of course.
But it usually seems to me that functionality that needs access to all the members of a List is properly the responsibility of that List (rather than the EditableRoot object of which that List object is a property). If the parent object needs the value of the weight of the entire collection, it can retrieve as simply as it gets the .Count propert of the List, right?
If you see it the same way, you just need to wire the handler suggested in Chris' post to the List object. The handler would presumably update the value of the List's new property (.Weight). When Parent needs it, they just use <ChildListName>.Weight.
Yeah, the parent would be respondent to the list saying "I've changed!".
The reason why the parent needs to know the list has changed isn't so much to do with object design per say in this case (the list could definitely have the sum too) but rather with Winforms databinding I believe - the parent's sum display won't automatically refresh unless you tell it to - so the parent needs to be able to subscribe to something that'll tell it when the sum changes so it can trigger this refresh.
(I work entirely in the Web but this is how I remember the issues in Win)
i need to bring this topic back up because I have a very similiar issue... I have a parent BO with child collection of childBOs... I have a property in my Parent BO cause LineItemsTotal that simply references the child collection property called LineItemsTotal which interns does the sumation of all the childrens LineItemTotal.
Now I can trap the ListChanged Event of the child collection object in my ParentBO... but there is no way to tell which property had changed? I do not want to fire off a PropertyHasChanged("LineItemsTotal") in my parent BO for every single item changed event in the child collection... the event would be fire thousands of times.
how do you find out which child bo property did the listchange event firing?
ward0093
ListChanged will tell you the property that changed, I'm pretty sure.
You'd also want to accomodate it for when an item is removed (and added if the default amount for that line is somehow non-zero).
edit: System.ComponentModel.ListChangedEventArgs e
i thought e.PropertyDescriptor was set to nothing but that is not true with the ItemChanged ListChanged Event arg type so that should work.
thanks,
ward0093
why is e.PropertyDescriptor is set to null when ListChangedType = ItemChanged? I can not evalulate it if the PropertyDescriptor is not set!
anyone have an answer to this?
ward0093
Copyright (c) Marimer LLC