CollectionEditor once again


G

Guest

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 CollectionEditor 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 CollectionEditor. 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 CollectionEditor 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 CollectionEditor'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 CollectionEditor class for refreshing the display, nor can I see any way of getting access to the CollectionEditor'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
 
Ad

Advertisements

M

Mick Doherty

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 said:
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 CollectionEditor 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 CollectionEditor. 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 CollectionEditor 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
CollectionEditor'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
CollectionEditor class for refreshing the display, nor can I see any way of
getting access to the CollectionEditor'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.
 
Ad

Advertisements

G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top