This project is read-only.

ObservableCollectionView does not support AddRange method

Sep 23, 2014 at 4:06 AM
Hi;

The AddRange Method as well as the Constructor of the ObservableCollectionView does not support passing a List of objects.

      In 2.3.6 ObservableCollectionView<T> can be instantiated like below:
private ObservableCollectionView<Notification> _criticalNotifications = new ObservableCollectionView<Notification>
        {
            new Notification(1, DateTime.Now, "Failed", NotificationType.Critial),
            new Notification(2, DateTime.Now, "Send error occurred", NotificationType.Critial),
            new Notification(3, DateTime.Now, "Incorrect login", NotificationType.Critial)
        };

//In 2.3.6 I can addrange of objects to a list and add the list to the ObservableCollectionView
// like below
List<Notification> moreNotifications = new List<Notification>
            {
                new Notification(4, DateTime.Now, "Test Test", NotificationType.Warning),
                new Notification(5, DateTime.Now, "ReTest", NotificationType.Information)
            };

            _criticalNotifications.AddRange(moreNotifications);

// Notification class
public Notification(long id, DateTime raisedDateTime, string description, NotificationType notificationType)
        {
            _id = id;
            _raisedDateTime = raisedDateTime;
            _description = description;
            _notificationType = notificationType;
        }

Once updated to 2.3.12, neither the constructor nor the AddRange method have any issues in the compile time but in the RunTime, MyToolKit throws a System.NotSupported exception and the Additional Information indicates the use of ObservableCollectionView.Add() method.
       My project is in a very mature state and there would be a lot of repercussions if I have to go back and retro fix this just for using 2.3.12 (which solves another bug)

       I would appreciate if you could answer my concerns
  1. Why is this being removed since it was working well
  2. Also, need to add the items to the ObservableCollectionView<T>.Items in order to avoid the exception
  3. Is there anyway, that we can keep using the AddRange method? (I tried the extension method with the same name but priority is given to the instantiated method and not the ext method).
Can you please help me with my concerns? Is there something that I am not doing right?

Please do not hesitate to ask me if you want more details.

Thanks,

Vinod
Sep 23, 2014 at 7:13 AM
You should use the class like described on https://mytoolkit.codeplex.com/wikipage?title=ObservableCollectionView
  1. Using the add remove, etc method is not allowed because a view is immutable, all these methods called the same method on the items property.
  2. Just use the source collection or the Items property to modify the source collection
  3. Use an ExtendedObservableCollection as source, it provides add range (you may cast the Items property to an ExtendedObservableCollection
Do you need the old functionality back? Maybe i can do something and mark it as obsolete..
Sep 23, 2014 at 7:36 AM
Ok, please try using MyToolkit 2.3.13... Add/Remove etc. should work as before... but you should use the ObservableCollectionView class as shown on the page https://mytoolkit.codeplex.com/wikipage?title=ObservableCollectionView
Sep 24, 2014 at 12:00 AM
Getting the latest 2.3.13 worked without any issues (as before) and also solves the other bug which was there in 2.3.6.

I got a better understanding of how to implement the ObservableCollectionView and will ensure that the correct way is followed in the future.

Thanks heaps for your prompt reply and for providing the upgrade in such a short time.

You are a champion!

Regards,

Vinod
Sep 24, 2014 at 7:30 AM
Thanks. If you like the project, please follow and review it..