Results 1 to 4 of 4

Thread: Application Settings and PropertyGrid

  1. #1

    Thread Starter
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Arrow Application Settings and PropertyGrid

    Hello guys,

    It has been a great discovery that you can make your application fully customizable for the user just adding a PropertyGrid to a form and setting its SelectedObject property as My.Settings object.

    VB Code:
    1. PropertyGrid1.SelectedObject = My.Settings

    In order to make your application customizable you have to:

    - Double Click on MyProject
    - Select the 'Settings' tab
    - Add all the settings you need by indicating:
    - Name for the property
    - Type (String, Color, Integer,ConnectionString...)
    - Scope (The scope of the property: user/application)
    - Value (The default value for this setting)
    - Now you can add this properties to any control in your form:
    - Click any control to select it
    - In the propertygrid of the control go to:
    (ApplicationSettings)>(PropertyBinding)
    - Now select any property and bind it to one of the settings you created before.
    - The last thing you have to do is adding a PropertyGrid to a form in your application and set:
    VB Code:
    1. PropertyGrid1.SelectedObject = My.Settings

    Thats all. The user can change the values of the settings on the propertygrid and all the controls within the application bound to these settings will show the changes.

    This is all quite simple. My question is:

    Is it possible to categorize the settings so you can group them in categories in the PropertyGrid? The user can see all the settings in the propertygrid, but can only change the properties which scope is "user". Is it possible to hide any of the properties?

    Thanks!!

  2. #2

    Thread Starter
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: Application Settings and PropertyGrid

    Any ideas? Perhaps adding or modifying some tags in the app.config file?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Application Settings and PropertyGrid

    Yes, you have to use attributes and specify the category that the property goes into by shadowing the prop.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: Application Settings and PropertyGrid

    Sorry, but I have no idea on how to do that. Let's say I have this simple app.config file:

    VB Code:
    1. <configuration>
    2.     <userSettings>
    3.         <MyApplication.My.MySettings>
    4.             <setting name="ButtonText" serializeAs="String">
    5.                 <value>I am a button</value>
    6.             </setting>
    7.             <setting name="ButtonBackColor" serializeAs="String">
    8.                 <value>Orange</value>
    9.             </setting>
    10.             <setting name="ButtonForeColor" serializeAs="String">
    11.                 <value>Black</value>
    12.             </setting>
    13.         </MyApplication.My.MySettings>
    14.     </userSettings>
    15. </configuration>

    How can I group both color properties under a Colors category and Buttontext setting under a "texts" category?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width