Link to home
Start Free TrialLog in
Avatar of johnftamburo
johnftamburo

asked on

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.
Avatar of magicdlf
magicdlf

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.
Avatar of johnftamburo

ASKER

If one writes XML out to a file in the same path as the program, it raises a UAC issue in Win7 and Vista.
Avatar of Éric Moreau
you can use the Users' settings of the App.Config. Check http://www.emoreau.com/Entries/Articles/2007/03/AppSettings-revisited.aspx
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.
ASKER CERTIFIED SOLUTION
Avatar of johnftamburo
johnftamburo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial