I have a project that is using CSLA 3.0.2.

I have a BusinessListBase collection object that has child items that have an IsDefault property.

When a child object has its IsDefault property set to true, I want to set the other child members IsDefault property to false.

I am calling the OnPropertyChanged("IsDefault") in the child setter and I have that raising the collections ListChanged event. However, the sender of the event is the Collection object, not the child object that raised the event. Nor is the child item in the ListChangedEventArgs (e).

How do I get a reference to the specific child instance that raised the event?

Or should I be doing this some other way? Like getting a reference to the parent in the child setter and doing it there?

Any help is appreciated.

1

There are 1 answers

0
tomRedox On

I started with CSLA at 3.6, but I think this will work in CSLA 3:

You should find there is an OnChildChanged method you can override in your BusinessListBase collection class. That method has a parameter of Csla.Core.ChildChangedEventArgs which contains a reference to the child object that changed, and which property of the object it was that changed.

You can then loop the other children in the collection in that method to set them to IsDefault = false.

protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
    base.OnChildChanged(e);

    switch (e.PropertyChangedArgs.PropertyName)
    {
        case "IsDefault":

            if ( ((ChildObjectType)e.ChildObject).IsDefault == true )
            {
                // then loop all the other childern 
                foreach (ChildObjectType child in this)
                {
                    if (child != e.ChildObject && child.IsDefault == true)
                    {
                        child.IsDefault = false; 
                    }
                }
            }
            break;
    }

}

If that doesn't work then the other approach is to use the Parent property in the child to get a reference to the collection and then call a method you have written in the BLB collection that updates the other children. You may need to look at the Parent's Parent depending on how your classes are set up.