views:

127

answers:

1

I have a question about a class I created that is similar to the ObserverableCollection. My class basically has the same same functionality as it, but I add some automatic sorting features to it when items are added to the List. My question is my class implements the interface INotifyCollectionChanged so that the ListView, which displays my collection, is notified when the collection changes (at least this is what I thought it did). Every time I add or remove from the collection I notify the collection has changed, but the ListView doesn't display the changes. So have I miss interpreted what INotifyCollectionChanged does? Should I be using INotifyPropertyChanged instead? Any help on the question would be great!

Here are the important parts of my class:

public class AscendingObservableCollection<T> : ICollection<T>, IEnumerable<T>, INotifyCollectionChanged
{

public event NotifyCollectionChangedEventHandler CollectionChanged;
...
protected void OnCollectionChanged()
    {
        CollectionChanged.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
    }
}

I call OnCollectionChanged() whenever the collection changes (item add/remove). I use NotifyCollectionChangedAction.Reset for all changes since my collection is a LinkedList and NotifyCollectionChangedEventArgs constructor needs an index for the NotifyCollectionChangedAction.Add/Remove flags which a LinkedList usually doesn't have.

My ListView which uses the collection uses Databinding on the ItemSource property for accessing the collection.

If you need more code let me know.

A: 

Ok I solved the problem after alot more step through debugging and searching. It turned out that the Notify stuff was working, but I had a small bug in the other section of my code that was causing it to break. Thanks every!

Josh