Refreshing the PropertyGrid

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
I have three alternative bits of code that I can use to refresh the property grid when a property changes other than through the user changing it through the propertygrid. These are shown below:

Visual Basic:
Public Class Form1
    Dim WithEvents h As New ABC

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.PropertyGrid1.SelectedObject = h
    End Sub

    Private Sub h_paintgrid() Handles h.paintgrid
        Me.PropertyGrid1.Refresh()
    End Sub
End Class
Public Class ABC

    Event paintgrid()
    Private def As Long
    <System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)> Public Property Def1() As Long
        'Option 1 = RefreshProperties.Repaint,   Option 2 = RefreshProperties.All
        Get
            Return def
        End Get
        Set(ByVal value As Long)
            def = value
            Me.Ghi1 = value & " *!$@"
            '   RaiseEvent paintgrid()  'Option 3
        End Set
    End Property

    Private ghi As String
    Public Property Ghi1() As String
        Get
            MsgBox("Property Queried")
            Return ghi
        End Get
        Friend Set(ByVal value As String)
            ghi = value
        End Set

    End Property

    Private jkl As Boolean
    Public Property Jkl1() As Boolean
        Get
            Return jkl
        End Get
        Set(ByVal value As Boolean)
            jkl = value
        End Set
    End Property

End Class

Each of them works OK to refresh the value shown for Ghi1 when Def1 is changed in the propertygrid and the focus is then moved away from Def1 (to Jkl1 for instance). But I have three questions:

1. Is there really any difference between Options 1 and 2? The help files say that RefreshProperties.All means that the properties will be requeried. But I get my message box even if RefreshProperties.Repaint is set and cannot see any difference between the two options.
2. Is there any argument against just using my event based Option 3 approach? I find this the simplest; and
3. Is there any way of just having the Ghi1 item refreshed in the propertygrid rather than the whole grid being refreshed each time? That would seem more efficient, if it can be done, especially in a larger grid.

EDIT: Option 3 seems to be better in fact because RefreshProperties only operates if the change is made by the user through the propertygrid, not if I make a change in code.
 
Last edited:
Back
Top