Child Object Needs to update other children

Child Object Needs to update other children

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


Norty posted on Friday, October 20, 2006

Using CSLA2.1

I have an object (Inherits BusinessBase), which contains a collection of child objects (Inherits BusinessListBase).  Each child object inherits BusinessBase.

My object is bound to a form, with the child collection bound to an editable datagirdview.  One of the properties of the child object is a boolean (check box in datagridview), and can be selected by the user.

However, this property can only be true for 1 of the child objects at any given time.  Is there any way for the child object to notify its parent collection to loop through all its children and take the necessary action?

Regards

Des Norton

Brian Criswell replied on Friday, October 20, 2006

Your child object can listen to the ListChanged event on the grandchild list.  If the type of change is ItemChanged, the property that changed will also be included.  If the boolean property changed and its value is true, the child object loops through its grandchildren and sets the boolean property to false if it is not already false.

Norty replied on Monday, October 23, 2006

Thanks Chris Big Smile [:D]

Works great.  Implemented slightly differently, though.

Loop through grandchildren, adding up number of true properties.  Set shared Grandchild.Property "NumberOfSelectedItems".  Custom validation rule enforces that shared property=1.

Possibly slightly more overhead, but the collection currently has 6 grandchildren, unlikely to ever reach double digits.  Also ensures a more consistant GUI.  User is shown all "Issues" and required to fix them before saving.

Regards

Des Norton

Copyright (c) Marimer LLC