Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CollectionBase and Updating an Item

CollectionBase and Updating an Item

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ryan Minor
    wrote on last edited by
    #1

    If you create a custom collection by deriving from CollectionBase, is there an easy way to fire an event when one of the collection items is updated? For example, any GUIs that care can subscribe to some sort of event that would be fired where an object that is a member of the collection is modified?

    N D 2 Replies Last reply
    0
    • R Ryan Minor

      If you create a custom collection by deriving from CollectionBase, is there an easy way to fire an event when one of the collection items is updated? For example, any GUIs that care can subscribe to some sort of event that would be fired where an object that is a member of the collection is modified?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      If you have created a custom class you can create whatever events make sense. For instance, in your override for the OnSet method fire off your custom event.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • R Ryan Minor

        If you create a custom collection by deriving from CollectionBase, is there an easy way to fire an event when one of the collection items is updated? For example, any GUIs that care can subscribe to some sort of event that would be fired where an object that is a member of the collection is modified?

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        Not that I know of. There are two easy options. 1. If you are using .NET framework 3.5 then add a reference to WindowsBase to your project. You can then use System.Collections.ObjectModel.ObservableCollection<T> which has an event CollectionChanged which should do what you want. 2. Make your own generic class and implement ICollection<T> and possibly ICollection. You can simply wrap a List<T> in this class to make implementation easier. Now you have control over all items in/out of the collection so can raise custom events as you like. [Edit] I've just had a look at the CollectionBase class and you should be able to override the necessary methods as they are protected virtual and raise your own event(s). OnClear, OnInsert, OnRemove, OnSet All these also have a protected virtual OnxxxComplete method too. [/Edit]

        Dave
        Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        modified on Sunday, March 21, 2010 10:09 AM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups