Question

I'm currently using My.Settings/Properties.Settings to store various user settings. Many of these settings are bound to controls in various Forms.

However I want a greater degree of control - specifically I would like to be able reload or save specific groups of settings. Using the in-built Settings.settings file, I can only handle these settings as a single group.

I know that I can create additional settings files, and this article (Summary section) suggests that if Settings.settings is not present, the application will look for other .settings files in the project root, but this doesn't seem to be the case for me (unless I am doing something wrong):

They offer tremendous power and flexibility. For example, you can add customized settings files to your project for management of settings in different groups. This allows you to save settings for a group or subset of values in separate files which can save saving and loading time.

I'm on the point of building my own Settings class and doing it all myself, but it would be a shame - the in-built functionality suits me well - providing I can have multiple settings files.

UPDATE: This article suggests that you can add additional settings files and drag them across to the Properties folder. Unfortunately, my current project is in VB.Net and this behaviour does not appear to be replicated.

Was it helpful?

Solution

The solution, it appears, is to add as many additional .settings files as needed. In the properties for each, add in a Customer Tool Name - in my case I chose 'My' to match the in-built Setting.settings.

Thereafter you can access each settings file independently, as follows:

My.Options1.Default.Foo = "bar"
My.Options2.Default.Foo = "bar"

My.Options1.Default.Save()
My.Options2.Default.Reload()

The .default is a minor annoyance, but other than that, this appears to work as I hoped.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top