Bulk Update Exception

6 posts, 0 answers
  1. Stefan
    Stefan avatar
    19 posts
    Member since:
    Jul 2012

    Posted 09 Aug 2012 Link to this post

    Hello,

    I'm using my own Collection Implementation and bind this to GridView 
    public class BindingTypedList<T> : Collection<T>, INotifyCollectionChanged
    {
        publicvoid AddRange(IList<T> items)
        {
            foreach(T item in items)
            {
                this.Add(item);
            }
            FireCollectionChanged(items);
        }
         
        public void FireCollectionChanged(IList<T> items)
        {
            try
            {
                if (CollectionChanged != null)
                    CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items.ToList()));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
        public event NotifyCollectionChangedEventHandler CollectionChanged;
    }
    I have an exception in FireCollectionChanged Funktion:

    ---------------------------
    Index must be within the bounds of the List.


    Parameter name: index
       at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)


       at System.Collections.Generic.List`1.Insert(Int32 index, T item)


       at Telerik.Windows.Data.KeyedCollection.Insert(Int32 index, Object value) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\KeyedCollection.cs:line 179


       at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1476


       at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1340


       at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1817


       at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1797


       at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33


       at FileExplorer.ViewModel.BindingTypedList`1.FireCollectionChanged(IList`1 items) in D:\Y\IZTMediaContainer\IZTMediaLibrary\ViewModel\DirInfo.cs:line 65
    ---------------------------


    Could you please help me.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 10 Aug 2012 Link to this post

    Hello,

    Similar to standard WPF components, RadGridView does not support NotifyCollectionChangedAction.Add with multiple items.

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Valerio
    Valerio avatar
    9 posts
    Member since:
    Sep 2014

    Posted 22 Jan 2015 in reply to Vlad Link to this post

    Hi,
    I'm having a similar issue trying to do the same, I subclassed the ObservableCollection to add an AddRange/RemoveRange operation for bulk insert/remove with optimized performance. Is this operation still not supported? Any plan to implement it in the near future?

    Regards,
    Valerio
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1217 posts

    Posted 22 Jan 2015 Link to this post

    Hi,

    With the current latest version, bulk add/remove operaions do not work with NotifyCollectionChangedAction.Add/NotifyCollectionChangedAction.Remove and this is a design concept we intend to follow in the future. Have you considered using RadObservableCollection<T>? It supports Suspend/Resume notifications, so that you can disable notifications before a bulk operation, preventing RadGridView from processing multiple event calls. When notifications are resumed NotifyCollectionChanged with reset action is raised.

    Regards,
    Ivan Ivanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Valerio
    Valerio avatar
    9 posts
    Member since:
    Sep 2014

    Posted 22 Jan 2015 in reply to Ivan Ivanov Link to this post

    Thanks Ivan,

    I just tried it and it works as expected. Thank you for the quick answer!

    Just for your reference, I was able to by-pass the problem by calling the CollectionChanged event using the NotifyCollectionChangedAction.Reset parameter instead of NotifyCollectionChangedAction.Add. In any case, it seems that the RadObservableCollection does what I need and therefore I will follow that path.

    Regards,
    Valerio
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1217 posts

    Posted 22 Jan 2015 Link to this post

    Hi,

    I am glad to hear that RadObservableColelction meets your requirements. I am closing the thread for now. Feel free to write back to us in case you need any further assistance.

    Regards,
    Ivan Ivanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top