PropertyGrid with specific user My.Settings

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
Hello all -

I know how to bind all the user scope settings into a propertygrid, however, what if I don't want the user to see ALL the user settings. What if I want to pick 6 of them to be placed within the propertygrid on one form and 10 on another form. Can I pick and choose which user scope settings appear in a propertygrid?


Code for all use scope settings (but I only need certain ones)

VB.NET:
        PropertyGrid1.SelectedObject = My.Settings

        '---display only user-scoped settings---
        Dim userAttr As New  _
           System.Configuration.UserScopedSettingAttribute
        Dim attrs As New  _
           System.ComponentModel.AttributeCollection(userAttr)
        PropertyGrid1.BrowsableAttributes = attrs


I am using visual studio 2008. Windows Forms.

Thanks
 
Last edited:
It would be simpler if you separated these settings in their own settings file, you would then have a separate settings object for each. You can do this by adding multiple .settings files to project. In VB Express add Text File but give it .settings extension rather than .txt extension, designer will be same as the default applications settings.
Remember these will not save automatically by application framework, you have to manually call their Save method before application closes, this can conveniently be done from application Shutdown event handler.
 
Thank you for the reply JohnH.... I am using Visual Studio 2008 Pro... How do I exactly add multiple settings files (or do you have a link to a tutorial)? I usually add my settings inside the project - under settings. Can I create a new settings file inside the project?

Thanks for your help.
 
Thanks JohnH - I figured it out.... I was placing in the wrong Project folder. (another program named the same)

You are amazingly smart in this subject....
 
Sorry to bother you again JohnH...

After I add another .settings file and include it in the project - how do I alter the code to call it for the property grid?

VB.NET:
   PropertyGrid1.SelectedObject = My.Settings

        ' Attribute for the user-scope settings. 
        Dim userAttr As New System.Configuration.UserScopedSettingAttribute
        Dim attrs As New System.ComponentModel.AttributeCollection(userAttr)
        PropertyGrid1.BrowsableAttributes = attrs

lets say my new file is "userinfosettings.settings"
 
PropertyGrid1.SelectedObject = userinfosettings.Default

You can see the Default property that expose the default instance of that settings file in the generated code. The application settings file has the same set up, but that also adds a wrapper My namespace around a MySettingsProperty module with a Settings property that returns the MySettings.Default object, thus the My.Settings interface for that.
 
Back
Top