Search code examples
vb.netwinformspropertygrid.net-4.5.2

PropertyGrid not working?


I have this class and I'd like it to be editable by means of a PropertyGrid control.

Class ConfigurationValues
    Public UpdateCapital As Boolean = False
    Public verbosity As VerbosityLevel = VerbosityLevel.e0_StrategyInformation
    Enum VerbosityLevel
        e0_StrategyInformation
        e1_HighLevel
        e2_BaseRoutines
        e3_Confirmations
        e4_AlmostAll
        e5_EveryThing
    End Enum
End Class

This is my form.

    Public Class Form1
        Dim config As New ConfigurationValues
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            PropertyGrid1.SelectedObject = config
        End Sub
    End Class

The problem here, is that the PropertyGrid stays blank.

Can someone enlighten me?


Solution

  • The PropertyGrid looks for properties. I also changed the Enum to be more readable - your choice though.

    Public Class ConfigurationValues
      Public Property UpdateCapital As Boolean = False
      Public Property verbosity As VerbosityLevel = VerbosityLevel.StrategyInformation
      Public Enum VerbosityLevel
        StrategyInformation
        HighLevel
        BaseRoutines
        Confirmations
        AlmostAll
        EveryThing
      End Enum
    End Class
    

    MSDN

    Code Project