Joey
Joey

Reputation: 354654

Is there a List<T> in .NET 2 that raises events when the list changes?

I have used ObservableCollection<T> in the past, but that seems to belong to WPF and therefore .NET 3.

And if there isn't what would be the appropriate interface for that? INotifyPropertyChanged seems not to be a very good fit for collections, while INotifyCollectionChanged is again only supported in .NET 3 and higher.

Upvotes: 4

Views: 1341

Answers (3)

Marcus Griep
Marcus Griep

Reputation: 8424

All of the collections in the C5 Generic Collection Library are designed to be able to raise events when an item is added, inserted, removed, or when the collection is cleared or otherwise changed. It provides a more robust interface for dealing with these changes than being held strictly to a list of objects, but also works with dictionaries, hash tables, priority queues, persistently sorted lists, etc.

Upvotes: 0

Simon P Stevens
Simon P Stevens

Reputation: 27499

The Collection<T> exposes virtual InsertItem, RemoveItem, SetItem and ClearItems methods that you could override and add your own events triggers to.

(Just a possible alternative to the BindingList<T>)

Upvotes: 2

Romain Verdier
Romain Verdier

Reputation: 13011

BindingList<T>

Upvotes: 13

Related Questions