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


Answer this question

Collection Events?

  • luca morelli

    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.


  • myNameIsRon

    Would the generic System.ComponentModel.BindingList class work for you

    Best regards,
    Johan Stenberg



  • RajPratapReddy

    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.

  • DaveFinley

    Yes, for now that might be the only option. Are those the only methods I'd have to override
  • Collection Events?