I need to save *dynamic* application settings in .NET 2.0 Winforms

I have a form that contains a datgridview.  It's called by about 100 classes, each of which use a different query to populate the datagridview, and the columns are dynamically set based on the dataset or bindingsource bound to the datagridview at runtime.

I need to allow the end user to reorder or hide/show the columns and developed a UI for it.  Now, I need to save the information, which is a long string of column information, 1 for each different way the form may be set up.  

I expected to be able to do something similar to resourcemanager, where you would encode .getstring("Settingname") or putstring("settingname"), that would to into the users or app's config file.

However, it appears that Microsoft in all of its sub-simian IQ, has build application settings so that you must define each and every one discretely at DESIGN time.

Is there ANY WAY AT ALL to use this in a REASONABLE manner, where I can dynamically get or put a string to a configuration key that is calculated and used at RUN TIME?

If not, is there any way to mimic this function with a few lines of code where it will not affect UAC in Vista or W7?

Please help.
Who is Participating?
johnftamburoConnect With a Mentor Author Commented:

This had the answer I needed.  I hate having to reinvent the wheel but it is the only way to do this.

The settings function built into .NET will NEVER allow a programmatically defined user setting.
I think you can create a class with strings to represent the columns. Then you just need to make the class XMLSerializable and save the XML file at the some place with your executables.
Take a look at this article: http://www.codeproject.com/KB/XML/GenericXmlSerialization.aspx
Feel free to ask if you have problems.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

johnftamburoAuthor Commented:
If one writes XML out to a file in the same path as the program, it raises a UAC issue in Win7 and Vista.
Éric MoreauSenior .Net ConsultantCommented:
you can use the Users' settings of the App.Config. Check http://www.emoreau.com/Entries/Articles/2007/03/AppSettings-revisited.aspx
johnftamburoAuthor Commented:
Only problem, emoreau, is that I will not know the name of the sertting until runtime.  That is the unspeakable horror of the present settings infrastructure; you cannot define new settings at runtime, everything must be defined at design time.  So, if I want to use the same form in 100 classes, each of whch binds its datagridview to different data, and customizes its actionsever so slightly, I am out of luck.

It seems that .NET is trying to force me to define 100 forms instead of one that is called by 100 classes and customized.  This is horribly inefficient and is contrary to the standards of OOP.

Is there no way of invoking My.Settings("Settingname")???  Without that, MS' own configuration settings management is horribly brittle.  I am being forced by Microsoft to reinvent the wheel by creating ANOTHER config file in XML.  I think that this is ridiculous.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.