CollectionEditor once again

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

    #1

    CollectionEditor once again

    Hi all

    I've been using the PropertyGrid to allow the user to edit a class object at runtime. The class object contains a custom strongly-typed collection, and I have written a subclass of CollectionEdito r to manipulate it, using an EditorAttribute on the collection class to associate the collection with my custom Editor subclass. The Collection Editor has its own little PropertyGrid, which displays the properties of the selected member of the collection. All OK so far..

    The issue arises when the user adds a new object to the collection using the Add button in the CollectionEdito r. In my collection class (which is derived from CollectionBase) I have overridden the OnValidate method to do a little tweaking of the object (adding an ID) before it is added to the collection. The way the CollectionEdito r seems to do this is by calling its CreateInstance( ) method to generate the new object, populating its local PropertyGrid with the new object's properties, then inserting it into the collection. The problem is that I am modifying the object's property values just before the new object inserted -- but this is AFTER the CollectionEdito r's local PropertyGrid has been loaded with the property values. Consequently what is displayed are the values PRIOR to the object's insertion, and the display is not refreshed! I can find no methods in the CollectionEdito r class for refreshing the display, nor can I see any way of getting access to the CollectionEdito r's PropertyGrid control. So the user won't see the real values of the new object's properties until he clicks OK, and then reopens the editor

    Any ideas? I realize this is a pretty arcane problem.. :-

    Thanks, MP
  • Mick Doherty

    #2
    Re: CollectionEdito r once again

    I am not seeing that behaviour here. If I modify the Object in the
    CollectionBase Class's OnValidate() Method
    then the Editor shows the modified property.

    "m. pollack" <anonymous@disc ussions.microso ft.com> wrote in message
    news:ED6955A6-6633-4906-A823-928EA2ADE0D8@mi crosoft.com...[color=blue]
    > Hi all,
    >
    > I've been using the PropertyGrid to allow the user to edit a class object[/color]
    at runtime. The class object contains a custom strongly-typed collection,
    and I have written a subclass of CollectionEdito r to manipulate it, using an
    EditorAttribute on the collection class to associate the collection with my
    custom Editor subclass. The Collection Editor has its own little
    PropertyGrid, which displays the properties of the selected member of the
    collection. All OK so far...[color=blue]
    >
    > The issue arises when the user adds a new object to the collection using[/color]
    the Add button in the CollectionEdito r. In my collection class (which is
    derived from CollectionBase) I have overridden the OnValidate method to do a
    little tweaking of the object (adding an ID) before it is added to the
    collection. The way the CollectionEdito r seems to do this is by calling its
    CreateInstance( ) method to generate the new object, populating its local
    PropertyGrid with the new object's properties, then inserting it into the
    collection. The problem is that I am modifying the object's property values
    just before the new object inserted -- but this is AFTER the
    CollectionEdito r's local PropertyGrid has been loaded with the property
    values. Consequently what is displayed are the values PRIOR to the object's
    insertion, and the display is not refreshed! I can find no methods in the
    CollectionEdito r class for refreshing the display, nor can I see any way of
    getting access to the CollectionEdito r's PropertyGrid control. So the user
    won't see the real values of the new object's properties until he clicks OK,
    and then reopens the editor.[color=blue]
    >
    > Any ideas? I realize this is a pretty arcane problem.. :-(
    >
    > Thanks, MP[/color]


    Comment

    • m. pollack

      #3
      Re: CollectionEdito r once again

      Hi Mick,

      hmmm... here's what I've found -- the display is updated, like you say, if I do nothing in OnValidate() besides modify the member value. However, I had been displaying a messagebox to the user at this point, and when I do that, then the grid only shows the pre-modification values.

      There must be some sort of threading issue here. I actually have to make some method calls to get the new values, and I'm wondering if we have a race going on, and if the result depends on how long it takes to fetch the values I need. I thought the whole thing would happen synchronously, but I guess not!

      Thanks, MP

      Comment

      Working...