How to Fire a Collection Changed Event on a Business List

How to Fire a Collection Changed Event on a Business List

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


thaehn posted on Thursday, October 16, 2014

I have a Telerik Grid with sum totals on the footer.  When a value in a child is changed the Grid does not recalculate the total.  The Grid requires a CollectionChanged event.  Is there a way to fire the event even though the list really did not change?  Here is a code example that doesn't work because the event is not accessible:

 

        /// <summary>

        /// The on child changed.

        /// </summary>

        /// <param name="e">

        /// The event args.

        /// </param>

        protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)

        {

            if (CollectionChanged != null)

            {

                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace));

            }

        }

 

Todd

 

JonnyBee replied on Friday, October 17, 2014

Hi Todd,

Have you tried this:

protected override void OnChildChanged(ChildChangedEventArgs e)
{
    base.OnCollectionChanged(new NotifyCollectionChangedEventArgs
        (NotifyCollectionChangedAction.Replace, e.ChildObject));
}

thaehn replied on Friday, October 17, 2014

Jonny,

That did not work, however, you set me on the right path!  I created a method that I call after all the values are changed which looks like this:

        /// <summary>

        /// The refresh.

        /// </summary>

        public void Refresh()

        {

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

        }

 

 

Microsoft's documentation says that "Reset" means the contents of the collection changed dramatically.  I have run into this problem several time and had to do some sort of workaround that I didn't really like such as crating dependencies in the UI by passing in the control from the View  to the ViewModel or by creating another property on the ViewModel that passed the property to the Model and raise the collection changed event.  This keeps it in the Business Layer which I like better.

Todd

Copyright (c) Marimer LLC