0

Essentially I'm looking for this type of project: http://www.codeproject.com/Articles/6160/Application-Configuration-Editor-using-the-Propert

But for the Application Settings. Have you heard of it, could you advice anything?

Basically the usecase is that once set, AppSettings could be changed only from the code and if you want to change anything by hand, you've got very limited and complex options.

The idea is to allow user to run the app with '--config' parameter and to allow him to change any setting there is in the interface that resembles Visual Studio's own editor:

enter image description here

Edit: of course, in runtime the only editable column should be Value. And the only other visible one should be Name, like here:

enter image description here

Gman
  • 1,781
  • 1
  • 23
  • 38
  • So you are going to cope with them changing name, type and scope? – Tony Hopkinson Aug 20 '12 at 17:18
  • No, only value. Left the note at the bottom of the question. See: http://www.codeproject.com/KB/cs/configeditor/configeditor.jpg that's more what I want. – Gman Aug 20 '12 at 17:20
  • What's wrong with the code project you linked? – CodingGorilla Aug 20 '12 at 17:20
  • @Coding Gorilla, It's designed to edit .exe.config files that architecturally are completely different from what AppSettings.settings are. In our project we prefer the latter. – Gman Aug 20 '12 at 17:24
  • Someone please correct me if I'm mistaken, the AppSettings.settings file generate a C# class which is compiled (as default values) into the application. The actual settings for the application settings are loaded from the .exe.config file (in the section). – CodingGorilla Aug 20 '12 at 17:26
  • Yes, they're compiled into program. Then settings are got from the compiled code, from DefaultSettingValueAttribute on the property you're accessing. But if you change the settings and call .Save(), then settings are stored in some %AppSettings%\Local\AppName\AppName.exe_Url_lotsofgarbage\version\user.config. – Gman Aug 20 '12 at 17:36

1 Answers1

2

Oh, haven't thought of it, just put your ApplicationSettingsBase into PropertyGrid.SelectedObject and you can edit it. Then you just call .Save() and your settings are saved.

Simple as that.

Edit: If you're building such an editor, consider adding the button that resets settings to their default values with the .Reset() method. By defaults I mean values that you specified in designer editor in Visual Studio.

With this button there're two main gotcha's:

First, after .Reset() is called, new (default) settings are already saved to disk, so there will be no obvious way of recovering them (if any at all). So, please, prepare your user for that.

Secondly, you'll need to call .Refresh() on your PropertyGrid, because it wouldn't refresh its fields (but when you'll set cursor to the field, it will refresh, so data is not saved, it's just still painted on the control).

Another edit: To make the process of editing settings even more user-friendly, you would probably want to organize them in groups, change names to more readable and such.

Unfortunately code for the settings object is autogenerated, which means that you can't add any attributes to the properties in that class. Fortunately, you can add these properties programmatically.

Community
  • 1
  • 1
Gman
  • 1,781
  • 1
  • 23
  • 38