views:

451

answers:

1

I have a class that has a readonly collection property - Its a list of extender providers that have been applied to the control.

I've implemented a simple property descriptor for the collection so that the property can be expanded in the property grid to examine each entry.

When I select an extender provider and set it to false, I remove it from the collection. The GetProperties method of the type converter is requeried and the property grid refreshes.

However, when I set an extender provider to true, and thus add it to the collection, GetProperties is not requeried.

Somehow, the property grid is making a distinction between adding to and removing from the collection. Or alternativly, its refreshing when an extender provider is added, but not when one is removed.

How can I get the grid to refresh when I add to the collection?

I've tried INotifyPropertyChanged and (PropertyName)Changed, but with no success.

ETA:

I've knocked together a small sample to demonstate my problem. For brevity, this sample uses an array and will persist, though not correctly. This does not effect the behaviour at design time though:

Public Class MyButton
    Inherits Button

    Private _Col As String()
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public ReadOnly Property Col() As String()
        Get
            Return Me._Col
        End Get
    End Property

    Private _AlterCol As String
    ''''''<RefreshProperties(RefreshProperties.All)> _
    Public Property AlterCol() As String
        Get
            Return _AlterCol
        End Get
        Set(ByVal value As String)
            _AlterCol = value
            ReDim Preserve Me._Col(Me._Col.Length)
            Me._Col(Me._Col.Length - 1) = value
        End Set
    End Property

    Public Sub New()
        ReDim Me._Col(2)
        Me._Col(0) = "Fred"
        Me._Col(1) = "Jim"
        Me._Col(2) = "Bob"
    End Sub

End Class

Now, to see the behaviour in action, add a MyButton to a form, expand the Col property and type some text into the AlterCol property.

The expanded sub properties in Col will not change. However, comment out RefreshProperties.All and it will be re-queried and updated.

My problem is that I am not updating Col from a Read/Write property. I'm updating it in response to an external provider being added. I need to force the property grid to refresh somehow. The only way I can think of doing it is a dummy property, decorated with RefreshProperties, that I assign a changed value to.

Any ideas?

A: 

Are you trapping the INotifyPropertyChanged...upon receiving the event you may need to "disconnect" the property grid, re-set it and refresh it...or are you not trapping the 'PropertyChanged' event of the property grid? Am a C# guy here...so this may render useless to you...?

// Within your trapping of the INotifyPropertyChanged Event Handler

    // Set 'SelectedObject' to null
    propGrid.SelectedObject = null;
    //
    propGrid.SelectedObject = this object
    //
    propGrid.Refresh();    

Here's an example of trapping the Property Changed....

private void propGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) {
       // Handle the property changed for the 'propGrid' conmponent
}

Edit: As Jules has pointed out, the need to do this was at design-time, so digging around I found something that might be enlightening on CodeProject...and here it explains how to leverage the usage of 'Extendee' used for controls...in order to get an insight into the problem.

It sounds like you need to make the class an extendee and bind it to the property grid at runtime...

Have a look here also on understanding IExtenderProvider here on CodeProject also, that explains how to use a CSS stylesheet and apply it to a windows form...

Hope this helps, Best regards, Tom.

tommieb75
Hi, I should have been clearer. This is at design time, so I have no access to the PropertyGrid Refresh method. I've amended the title to clarify.
Jules
@Jules: Ahhhh..ok...thanks for your response :)
tommieb75