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
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