Suggestion - more events for ExtendedBindingList: InsertingItem, ItemInserted, ItemRemoved

Suggestion - more events for ExtendedBindingList: InsertingItem, ItemInserted, ItemRemoved

Old forum URL: forums.lhotka.net/forums/t/6422.aspx


oscarmorasu posted on Friday, February 13, 2009

Hello,

Right now all our collections inherit from BusinessListBase. We have a parent class "P" that contains a BusinessListBase "L".

Under many scenarios I want P to know if an item is being inserted, was inserted, is being removed or was removed from L. CSLA 3.6.1 already has an event ExtendedBindingList.RemovingItem that triggers from the override of RemoveItem. Any subscriber can hook up to that event and execute some logic (such as validation) before the item is removed from the list.

I think it would be very helpful to have an InsertingItem and ItemInserted events in the override of InsertItem, before and after calling base.InsertItem(), as well as an ItemRemoved event in the override of RemoveItem, after base.RemoveItem() is called.

Thanks.

RockfordLhotka replied on Friday, February 13, 2009

The reason I added RemovingItem is that it was impossible to get a reference to the item being removed from the ListChanged event, since that event only provides an index - which is invalid by the time you get the event.

I suppose I could see RemovedItem having some value, and if there's a compelling real scenario for it I'll consider it.

Insert, Move and Set operations can be handled by ListChanged, because in those cases the index values are valid and give you access to the item(s) affected.

Realistically, this whole list model is a little up in the air though, due to the conflict between WPF and Windows Forms. That's covered rather extensively in a different thread from a couple weeks ago.

So in all honesty, I'm unlikely to make changes to the existing collection types (other than bug fixes) until I know how I'm going to address the BindingList<T> base vs ObservableCollection<T> base issue.

oscarmorasu replied on Monday, February 23, 2009

Thanks for the answer Rocky.

Just like you said, the RemovingItem is very helpful since it provides the item before it's removed. However, in my scenario the parent class has to know when the item was already removed from the collection. ListChanged only provides the index of the item, which is no longer valid.

Also, ListChanged doesn't cover the ItemInserting scenario. In this case I want the parent class to be notified an item is being inserted, and run some logic and validation before the insert actually takes place.

I understand you are not able to include these changes in your current version. Just keep it in mind as a possible future enhancements. In the meantime I'm overriding InsertItem and RemoveItem to include the events mentioned above.

Copyright (c) Marimer LLC