1

Possible Duplicate:
CollectionView.DeferRefresh() throws exception

What i dont understand:

I have an ObservableCollection which serves as the source collection for a ListCollectionView.

When i modify the ObservableCollection (Clearing and adding new items) in the scope of a DeferRefresh on the ListCollectionView then an exception is thrown.

    var observableCollection = new ObservableCollection<string>();
    var collectionView = new ListCollectionView(observableCollection);

    var items = new List<string> { "1", "2", "3", .. "999" };

    using (collectionView.DeferRefresh())
    {
      observableCollection.Clear();

      foreach (string item in items)
      {
        observableCollection.Add(item);
      }
    }

throws System.InvalidOperationException : Cannot change or check the contents or Current position of CollectionView while Refresh is being deferred.

It would be nice to not refresh the CollectionView until all the add operations (could be 100-1000) are completed.

How can i achieve this?

Community
  • 1
  • 1
leozilla
  • 1,296
  • 2
  • 19
  • 29
  • 1
    What kind of an exception is thrown? – MatthiasG Jan 11 '12 at 20:19
  • 1
    System.InvalidOperationException : Cannot change or check the contents or Current position of CollectionView while Refresh is being deferred. – leozilla Jan 11 '12 at 21:00
  • See this identical question: [CollectionView.DeferRefresh() throws exception](http://stackoverflow.com/q/6032132/620360). – LPL Jan 11 '12 at 21:57

0 Answers0