Settings.settings and custom types

G

Guest

I am trying to use a custom type inside settings.settings. When I create my
class, I am able to add it in as the type and the value ends up showing as
XML data. If I change any of the values in my class, the values do not
update the settings file. Can anyone provide any insight and/or sample code
on how to use a user defined class as a valid and usable type in the
settings.settings file?

Thanks,
--Rob.
 
K

Kevin Spencer

It must be a User-scoped Setting, and you must save the Settings prior to
closing the app.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

Kevin:

Thanks for the response. I have the setting scoped as user, and I do call
the save method.

What I am looking to do is, lets say I have a class like this:

class MyClass
{
public int firstVariable;
public int secondVariable;
public string someString;
}

and I want to store the values of this class in the settings.settings, so in
the settings designer I chose "MyApp.MyClass" as the type with the scope of
user and the tool generated a block of XML in the app.config file. I am able
to get the settings by reading
Properties.Settings.Default.MyClass.firstVariable, etc., however, I am unable
to update and save the values back to the config file.

Any ideas?

Thanks,
--Rob.
 
K

Kevin Spencer

Are you assigning the Settings class instance to a variable, and saving that
at the end, or creating another instance and saving that at the end? If you
reference the actual instance in the Settings, when you save it should be
serialized back.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top