Collection Events?

I was wondering if there is a way to monitor a collection (eg StringCollection) for changes.

Back in the Delphi world, there was a class called TStringList, which was essentially the same thing, and it had an OnChanged event, which enabled you to listen for changes to the list.

I think a Change event in the standard collection classes would be immensely helpful - or is there already a collection class with a Change event that I haven't found?

If no such animal exists ... would it be worth petitioning to have an event added to the base collection classes for a future release?

Cheers,
mabster

[611 byte] By [mabster] at [2007-12-16]
# 1
I agree it would be handy to add a Changed event on Collection.

However, it wouldn't be too hard to derive from Collection<T> and override the ClearItems, InsertItem, RemoveItem and SetItem methods to raise a Changed event.

DavidM.Kean at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Yes, for now that might be the only option. Are those the only methods I'd have to override?
mabster at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
Would the generic System.ComponentModel.BindingList class work for you?

Best regards,
Johan Stenberg

JohanStenberg at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4
Possibly. I'm just using a collection to keep track of most recently used files. I wanted to catch the change event so I could update my File menu.

I'll check it out. Thanks.

mabster at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified