Child Objects Loosing Event Handlers

Child Objects Loosing Event Handlers

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


RyanL posted on Tuesday, October 02, 2007

CSLA 2.14

 

I have a parent object called Driver.  He has an editable list of child objects called Accessories on him.  So in other words it looks like this:

Driver (BusinessBase(Of Driver))

            AccessoryList(BusinessListBase(Of AccessoryList, Accessory))

                        Accessory(BusinessBase(Of Accessory))

 

AccessoryList and Accessory were modeled after ProjectResource and ProjectResources in ProjectTracker20vb and from what I can tell have no differences.

 

After I call save on my parent object Driver which in turn saves the list of Accessories, the list of Accessories no longer have any event handlers.  The reason this has come up in our situation is because we are calling save in our Windows form and leaving the form up after the save.  If you then try to change a property on the child object the object no longer gets flagged as dirty or savable.  However, if you change one of the parents properties the object then gets flagged as savable and works fine. 

 

It seems as though the child object looses its PropertyHasChanged event handlers and no longer flags the object as dirty, nor does it check the validation rules.

 

Has anyone run into this situation?  Why is the parent object keeping its event handlers and the children not?

 

RockfordLhotka replied on Tuesday, October 02, 2007

It is important to remember that Save() returns a new object - including new child objects.

You are probably re-binding the root object, Driver, and are not re-binding the child collection, so your UI is still bound to the old object, not the current "real" object.

Or, if your Driver object is handling the ListChanged event of its child collection, that will get lost during deserialization of an object graph (with a remote data portal). You need to rehook that even in the OnDeserialized() override in Driver. This only matters if you hook the ListChanged event and use it to trigger raising an OnUnknownPropertyChanged() call in Driver.

Copyright (c) Marimer LLC