By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

CollectionEditor once again

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
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

Nov 22 '05 #2

P: n/a
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
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.