1

I am getting this exception when I am trying to Delete the item from Dictionary which I am inheriting from INotifyCollectionChanged. When I am deleting for first time I am able to delete the item, just after that if i am trying to delete this exception comes though when I try to look into the collection the item is there at that position(2 in this case). What could be wrong here. Adding the code snippet where the exception is coming

CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new KeyValuePair(key, value), i));

Vikram
  • 1,617
  • 5
  • 17
  • 37
  • What exception do you get? Also it would be easier to solve you problem if you show more code. – icebat Dec 02 '11 at 06:42
  • the exception is "Added item does not appear at given index '2'" – Vikram Dec 02 '11 at 10:25
  • public bool Remove(IClass key) { int i = -1; foreach(KeyValuePair<(IClass, IClass1> KeyValuePair in _list) { i++; if (KeyValuePair.Key.Equals(key)) break; } IClass1 value = this[key]; CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new KeyValuePair(key, value), i)); return _list.Remove(key); } This is one of the function for my collection class. – Vikram Dec 02 '11 at 10:31
  • Did you ever solve this? I'm struggling with something similar. – J23 Oct 17 '20 at 06:10

0 Answers0