CollectionBase OnInsert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • m. pollack

    #1

    CollectionBase OnInsert

    Hi all,

    I have subclassed the CollectionEdito r object in order to
    override its OnInsert and OnRemove methods (because I am
    exposing some properties (including a collection property)
    of a class object at runtime with a PropertyGrid, and
    needed to know when the user was adding objects to, or
    removing objects from, the collection. My question is: Can
    I use the OnInsert method to block the user from modifying
    collection if the object to be added/removed fails some
    test? OnInsert and OnRemove just return "void", so I don't
    see how, but the docs suggest that it can be done.

    One complication of using the CollectionEdito r is that it
    seems not to add/remove objects by calling the collection
    class's Add or Remove methods (removal, for instance,
    seems to just happen somehow via
    (CollectionEdit or.DestroyInsta nce()), but rather by
    grabbing the whole inner list, working with it "offline",
    and then just plunking it back in.

    Any ideas?
  • Mick Doherty

    #2
    Re: CollectionBase OnInsert

    You can stop the user adding an object to the collection by throwing an
    Exception/ArgumentExcepti on in the OnValidate methods of the CollectionBase
    class. This will force the user to either correct the Object or remove it.

    You can use the CollectionEdito r's CanRemoveInstan ce() Method to stop the
    user removing an object.

    "m. pollack" <anonymous@disc ussions.microso ft.com> wrote in message
    news:0de201c3da b6$985842d0$a30 1280a@phx.gbl.. .[color=blue]
    > Hi all,
    >
    > I have subclassed the CollectionEdito r object in order to
    > override its OnInsert and OnRemove methods (because I am
    > exposing some properties (including a collection property)
    > of a class object at runtime with a PropertyGrid, and
    > needed to know when the user was adding objects to, or
    > removing objects from, the collection. My question is: Can
    > I use the OnInsert method to block the user from modifying
    > collection if the object to be added/removed fails some
    > test? OnInsert and OnRemove just return "void", so I don't
    > see how, but the docs suggest that it can be done.
    >
    > One complication of using the CollectionEdito r is that it
    > seems not to add/remove objects by calling the collection
    > class's Add or Remove methods (removal, for instance,
    > seems to just happen somehow via
    > (CollectionEdit or.DestroyInsta nce()), but rather by
    > grabbing the whole inner list, working with it "offline",
    > and then just plunking it back in.
    >
    > Any ideas?[/color]


    Comment

    • m. pollack

      #3
      Re: CollectionBase OnInsert

      Hi Mick,

      Thanks again for responding.
      OnValidate? I'll give that a go. I am interested in being
      able to substitute a different object for the one being
      added - in other words I want to replace the object
      created by the Editor with a same-type object of my own
      creation, with various settings of its data members. I'm
      hoping I can do something like simply replace the object
      reference of the passed-in argument with the new one.
      Anyway, I'll try.. thanks!

      PS ...you'd think they might make this gizmo a little more
      developer-friendly! Wherever there is user input,
      developers are going to want to control the process --
      this CollectionEdito r does all of this in avery non-
      intuitive way (why, for example, can't OnInsert, instead
      of returning 'void', return a bool that cancels the
      operation if false?). If it would simply call the
      appropriate methods in the collection class (Remove, Add,
      etc.) instead of all this behind-the-scenes monkeying
      about, life would be much simpler...

      MP

      [color=blue]
      >-----Original Message-----
      >You can stop the user adding an object to the collection[/color]
      by throwing an[color=blue]
      >Exception/ArgumentExcepti on in the OnValidate methods of[/color]
      the CollectionBase[color=blue]
      >class. This will force the user to either correct the[/color]
      Object or remove it.[color=blue]
      >
      >You can use the CollectionEdito r's CanRemoveInstan ce()[/color]
      Method to stop the[color=blue]
      >user removing an object.
      >
      >"m. pollack" <anonymous@disc ussions.microso ft.com> wrote[/color]
      in message[color=blue]
      >news:0de201c3d ab6$985842d0$a3 01280a@phx.gbl. ..[color=green]
      >> Hi all,
      >>
      >> I have subclassed the CollectionEdito r object in order[/color][/color]
      to[color=blue][color=green]
      >> override its OnInsert and OnRemove methods (because I am
      >> exposing some properties (including a collection[/color][/color]
      property)[color=blue][color=green]
      >> of a class object at runtime with a PropertyGrid, and
      >> needed to know when the user was adding objects to, or
      >> removing objects from, the collection. My question is:[/color][/color]
      Can[color=blue][color=green]
      >> I use the OnInsert method to block the user from[/color][/color]
      modifying[color=blue][color=green]
      >> collection if the object to be added/removed fails some
      >> test? OnInsert and OnRemove just return "void", so I[/color][/color]
      don't[color=blue][color=green]
      >> see how, but the docs suggest that it can be done.
      >>
      >> One complication of using the CollectionEdito r is that[/color][/color]
      it[color=blue][color=green]
      >> seems not to add/remove objects by calling the[/color][/color]
      collection[color=blue][color=green]
      >> class's Add or Remove methods (removal, for instance,
      >> seems to just happen somehow via
      >> (CollectionEdit or.DestroyInsta nce()), but rather by
      >> grabbing the whole inner list, working with[/color][/color]
      it "offline",[color=blue][color=green]
      >> and then just plunking it back in.
      >>
      >> Any ideas?[/color]
      >
      >
      >.
      >[/color]

      Comment

      Working...