none
Adding description and category to my.settings via Settings.Designer.vb? RRS feed

  • Question

  • I want to use the PropertyGrid to let users change the settings of my vb.net program

    I simply put

           PropertyGrid1.SelectedObject = My.Settings
    

    It works pretty nicely, but it would be even nicer if the settings could be categorized and described.

    I found that I can edit the Settings.Designer.vb file, adding description and category like this

     

           <Global.System.Configuration.UserScopedSettingAttribute(),  _
             Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
             Global.System.Configuration.DefaultSettingValueAttribute("c:\barcode\Barcode+text.lbx")>
            <Description("Path to the barcode template file"), Category("Barcode")>
            Public Property Barcode() As String
                Get
                    Return CType(Me("Barcode"),String)
                End Get
                Set
                    Me("Barcode") = value
                End Set
            End Property
    

    With this the settings look even nicer.

    Unfortunately the added <Description, Category> disappears when I add new settings to the program, because the file is auto-generated.

    Is it possible to put description and category somewhere else ? so it doesn't get deleted by auto-generated files?

    Cheers,

    Jesper


    • Edited by JesperSP Monday, January 20, 2020 11:46 AM
    Saturday, January 18, 2020 4:06 PM

Answers

  • Hello,

    As you learned, don't make changes to the designer. I've written a simple way to handle what you are looking for as per the following.

    https://social.technet.microsoft.com/wiki/contents/articles/52295.vb-net-my-settings-deep-dive.aspx#My_Settings_customization


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JesperSP Thursday, January 23, 2020 8:03 AM
    Saturday, January 18, 2020 7:37 PM
    Moderator
  • Hi JesperSP, 

    Thank you for posting here.

    For your question, you can create a class and show it on PropertyGrid with description and category.

    Here’s the code of my test.

            Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim data As Data = New Data With {
                .Path = "c:\barcode\Barcode+text.lbx",
                .Number = 1
            }
            PropertyGrid1.SelectedObject = data
        End Sub
        Class Data
            <Description("Path to the barcode template file")>
            <Category("Barcode")>
            Public Property Path As String
            <Description("Number")>
            <Category("Barcode")>
            Public Property Number As Integer
        End Class
    

    Result:

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JesperSP Thursday, January 23, 2020 8:03 AM
    Sunday, January 19, 2020 7:15 AM
    Moderator

All replies

  • Hello,

    As you learned, don't make changes to the designer. I've written a simple way to handle what you are looking for as per the following.

    https://social.technet.microsoft.com/wiki/contents/articles/52295.vb-net-my-settings-deep-dive.aspx#My_Settings_customization


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JesperSP Thursday, January 23, 2020 8:03 AM
    Saturday, January 18, 2020 7:37 PM
    Moderator
  • Hi JesperSP, 

    Thank you for posting here.

    For your question, you can create a class and show it on PropertyGrid with description and category.

    Here’s the code of my test.

            Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim data As Data = New Data With {
                .Path = "c:\barcode\Barcode+text.lbx",
                .Number = 1
            }
            PropertyGrid1.SelectedObject = data
        End Sub
        Class Data
            <Description("Path to the barcode template file")>
            <Category("Barcode")>
            Public Property Path As String
            <Description("Number")>
            <Category("Barcode")>
            Public Property Number As Integer
        End Class
    

    Result:

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JesperSP Thursday, January 23, 2020 8:03 AM
    Sunday, January 19, 2020 7:15 AM
    Moderator
  • As you learned, don't make changes to the designer. I've written a simple way to handle what you are looking for as per the following.

    Thanks for your suggestion!. You write that it is simple. It's a bit more complicated than simply setting "PropertyGrid1.SelectedObject = My.Settings". With your suggestion I  have to make a complete copy of the settings to set this up. And if I add new settings I will have to add the also to the MySettings

    Monday, January 20, 2020 11:12 AM

  • For your question, you can create a class and show it on PropertyGrid with description and category.

     Thanks for your suggestion. It's a bit more complicated than simply setting "PropertyGrid1.SelectedObject = My.Settings". 
    Monday, January 20, 2020 11:14 AM
  • I chose a slightly different route : 

    I made a new MySettings class, and bind this to the PropertyGrid:

    Public Class MySettings
        <Description("Path to the barcode template file"), Category("Barcode")>
        Public Property Barcode() As String
            Get
                Return CType(My.Settings.Barcode, String)
            End Get
            Set
                My.Settings.Barcode = Value
            End Set
        End Property
    End Class

    It is annoying that I have to add settings here also, but I will have to live with it.

    I would suggest Microsoft adds the description and category to the Project -> settings  of visual studio:)

    Cheers,

    Jesper

    Monday, January 20, 2020 1:58 PM
  • Hi JesperSP, 

    Thanks for your feedback.

    >> I would suggest Microsoft adds the description and category to the Project -> settings  of visual studio:)

    You can suggest a feature in Developer Community forum.

    Besides, if your problem has been solved, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 22, 2020 5:25 AM
    Moderator