Friday, May 6, 2011

Visual C# "Settings Editor" within application?

Is there an easy way to wrap a "Preferences Panel" thing around the Settings.settings file (or any other settings file)?

Basically I have a bunch of strings stored in Settings.settings, and want to have a form where the user can edit these..

I could add a bunch of TextBoxes, and have a button that does Properties.blah = this.blahInput.Text; Properties.Save(); for each, but this feels like reinventing the wheel..

Edit: The PropertyGrid control (as suggested by bassfriend's) seems perfect, but I cannot work out how to bind the property grid's SelectedObject to Properties.Settings.Default - When I try I get the following error:

Cannot implicitly convert type 'MyProject.Properties.Settings' to 'object[]'
From stackoverflow
  • Maybe you want to take a look at the PropertyGrid Control.

    Peter Lillevold : For the record - there is also a WPF PropertyGrid over at CodePlex http://www.codeplex.com/wpg
  • I had no problem:

            propertyGrid1.SelectedObject = Properties.Settings.Default;
    

    I did have to change the visibility to Public in the Settings Designer.

    dbr : Opps, I was trying to set "SelectedObjects", not "SelectedObject".. Thanks!
  • Maybe you need to use the Settings.Default.Properties property? That returns SettingsPropertyCollection which should be convertable to an object[].

    dbr : Nah, I was trying to set "SelectedObjects", not the singular "SelectedObject"..

0 comments:

Post a Comment