WPF grid throws exception when CollectionChanged fires on ItemsSource

3 posts, 0 answers
  1. Will
    Will avatar
    27 posts
    Member since:
    Jun 2008

    Posted 06 Jun 2008 Link to this post

    Hi,

    We are just experimenting with the RadGridView in the WPF controls and have found that when we bind to an observable collection, CollectionChanged events cause the grid to throw an exception:

    "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
       
       at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
       at Telerik.Windows.Controls.Core.Data.VirtualizingRecordCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at Telerik.Windows.Controls.Core.Data.VirtualizingRecordCollection.Reset()
       at Telerik.Windows.Controls.Core.Data.VirtualizingRecordCollection.set_RealRecords(IList`1 value)
       at Telerik.Windows.Controls.Core.Data.RecordManager.RecalculateGroups()
       at Telerik.Windows.Controls.Core.Data.RecordManager.ResetRecords()
       at Telerik.Windows.Controls.Core.Data.RecordManager.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at Telerik.Windows.Controls.Core.Data.RecordManager.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
       at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
       at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
       at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
       at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)

    This looks to be a bug in the grid as we haven't experienced this with the other WPF grids we tried. Do you know of a work around?

    Many thanks,

    Will Holley
  2. Will
    Will avatar
    27 posts
    Member since:
    Jun 2008

    Posted 09 Jun 2008 Link to this post

    Just an update to this - we have solved it for now by proxying our source collection through a class which forwards all CollectionChanged events to the Dispatcher thread - doesn't seem ideal but it works.

    see How to propagate changes across threads in WPF? for an example of something similar.
  3. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 10 Jun 2008 Link to this post

    Hi Will,
    Thanks for the feedback. I think the problem is related to propagating changes across threads.
    Such problems are very well explained in the following blog post: http://www.beacosta.com/blog/?m=200609

    I modified a little the Beatriz Costa's example and just changed the ListBox control with Telerik RadGridView for WPF and all seems to work fine. See attachment for the modified example.

    Should you have any additional questions/problems don't hesitate to contact us.

    Kind regards,
    Nedyalko Nikolov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top