views:

248

answers:

2

I've got a custom class which can be edited through the PropertyGrid. In that class I've got a custom Collection (with custom PropertyDescriptor and TypeConverter).

Items can be added to or removed from the Collection with the default Collection Editor. This all works fine. But - after closing the Collection Editor, the PropertyGrid is not updated. When I manual make a call to Refresh() on the PropertyGrid, the changes are reflected in the PropertyGrid.

How can I get the PropertyGrid to automatically refresh when the Collection Editor has been closed? I sought for a solution earlier where I should subclass CollectionEditor (which I can't seem to find).

Please help.

A: 

RefreshPropertiesAttribute Class

Indicates that the property grid should refresh when the associated property value changes. This class cannot be inherited.

Inserted from http://msdn.microsoft.com/en-us/library/system.componentmodel.refreshpropertiesattribute.aspx

Adding Attribute with Descriptor

        Public Overrides ReadOnly Property Attributes() As System.ComponentModel.AttributeCollection
            Get
                Return New AttributeCollection(New Attribute() {RefreshPropertiesAttribute.Repaint})
            End Get
        End Property

Walkthrough: Debugging Custom Windows Forms Controls at Design Time at http://msdn.microsoft.com/en-us/library/5ytx0z24.aspx

AMissico
I've tried that and I doesn't work. When I add 1 item to the Collection when it's empty, the PropertyGrid gets updated. When I add another item, nothing happens until I manually refresh...
MysticEarth
I have had that happen before. The problem is in your classes. I suggest debugging the design-time of your control.
AMissico
I think it had something to do with the type-converter, convert-to,
AMissico
A: 

You might also try adding the NotifyParentProperty attribute to the collection. This has worked for me in similar situations.