How to: Create Property Grids for User Settings in Visual Basic
You can create a property grid for user settings by populating acontrol with the user setting properties of the My.Settings object.
In order for this example to work, your application must have its user settings configured. For information on adding user settings, see.
The My.Settings object exposes each setting as a property. The property name is the same as the setting name, and the property type is the same as the setting type. The setting's Scope determines if the property is read-only; the property for an Application-scope setting is read-only, while the property for a User-scope setting is read-write. For more information, see.
You cannot change or save the values of application-scope settings at run time. Application-scope settings can be changed only when creating the application (through the Project Designer) or by editing the application's configuration file. For more information, see.
This example uses a PropertyGrid control to access the user-setting properties of the My.Settings object. By default, the PropertyGrid shows all the properties of the My.Settings object. However, the user-setting properties have theattribute. This example sets the property of the PropertyGrid to UserScopedSettingAttribute to display only the user-setting properties.
To add a user setting property grid
Add the PropertyGrid control from the Toolbox to the design surface for your application, assumed here to be Form1.
The default name of the property-grid control is PropertyGrid1.
Double-click the design surface for Form1 to open the code for the form-load event handler.
Set the My.Settings object as the selected object for the property grid.
Configure the property grid to show only the user 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
To show only the application-scope settings, use theattribute instead of UserScopedSettingAttribute.
The application saves the user settings when the application shuts down. To save the settings immediately, call the My.Settings.Save method. For more information, see.