BusinessListBase with multiple LinqObservableCollections

BusinessListBase with multiple LinqObservableCollections

Old forum URL:

dazzford posted on Wednesday, September 05, 2012

Hi Folks,

I've got a BusinessListBase with multiple LinqObservableCollections (LOC) pointed at it. I've noticed a few things.

1) when a new object is added to the BusinessListBase, that object appears in all filtered lists, without conforming to the filter (understandably so since the LINQ query returns an enumeration). 

2) when an object is deleted from the original list the LOCs which do not have that object in their list, throw an InvalidOperationException stating "Cannot find removed item." When the LOCs are not databound, the exception is not thrown. 

The first is minor, the second is a little bigger of an issue.

Since the LOC is a filtered view, in the lamda expression which handles the _baseCollection.CollectionChanged event (line 54 of LinqObservableCollection) we check the returned indexes to see if they are > -1.

case NotifyCollectionChangedAction.Remove:

item = (T)e.OldItems[0];
index = _filteredCollection.IndexOf(item);
if(index > -1)
newE = new NotifyCollectionChangedEventArgs(e.Action, item, index);

I apologize if I have not formatted things correctly, I'm not sure if there are any code tags on this forum.



RockfordLhotka replied on Thursday, September 06, 2012

Thank you, I'll file this as a bug.

RockfordLhotka replied on Monday, February 25, 2013

Interestingly enough, I have been unable to create a failing unit test for this issue.

Still, the code change you propose makes sense, so I've made this change to 4.5.13.

Copyright (c) Marimer LLC