Click here to Skip to main content
Click here to Skip to main content

Application Configuration Editor using the PropertyGrid

, 1 Mar 2004
Rate this:
Please Sign up or sign in to vote.
An application configuration editor using the PropertyGrid control.
<!-- Article image -->

Sample Image - configeditor.jpg

<!-- Add the rest of your HTML here -->


Since I discovered configuration sections and configuration section handlers, I've been using custom configuration sections to hold a variety of runtime required settings. What I've wanted for some time now was an easy way to edit these sections, either for simple application setting changes, or during deployment as a custom installation action. In this article I'll describe the approach and logic to the development of my own configuration editor. Download the source code and run the project to see the application in action.


The first example of a custom configuration handler I came across was in the sample Duamish7 application that ships with the .NET Framework SDK. I confess my first reaction was 'oh my god'. It looked like a lot of code to implement the equivalent of a few registry settings. Looking back I can see why I was initially skeptical about their value. Even without using a custom configuration section handler the .NET Framework Class Library supplies a simple NameValue section reading class in System.Configuration.ConfigurationSettings.AppSettings - for quick and easy reading of any setting in the <appSettings> section. It wasn't until recently that I discovered the true value of a custom configuration handler. By handling the section yourself you are no longer limited to simple key value pair attributes. In fact you can build your own XML structure altogether and do what ever you want with this when the node for your section is passed to the handler. There are a lot of excellent resources out there that describe how to implement your own custom configuration section handler and so that's not the topic here, although I'll include several links to them below. What you will see in this application however is the value of handling a section yourself, in a simple way. I've extended the name value pair keys to include an additional XML attribute for the setting, the 'description' attribute which you can see in action in the screen shot above.

Enter the PropertyGrid control. It turns out that the PropertyGrid is perfectly suited for this application. I wanted a two column grid with the first column readonly, and the second column editable and the whole thing divided nicely into categorized sections. I've seen at least one other attempt at creating a Configuration file editor using the DataGrid and a DataSet however it just didn't seem as elegant a solution as using the PropertyGrid. If you're wondering where the PropertyGrid control comes from you'll be pleased to know you already have it, it's free to use as a .NET control, you just need to add it to the toolbar in Visual Studio.

Dynamic Properties. Having chosen the tools and controls I was faced with a problem - how to effectively de-serialize the configuration sections I was interested in, creating an object that could be used for the PropertyGrid's SelectedObject property. The PropertyGrid is an impressive control. It will automatically display all the properties of a class, along with property values which can be edited. How you create the object and what you do with it when you're finished changing values is the 'interesting' part. There is a LOT of customization options that will determine how values are displayed in the property grid. Again there are links below to the MSDN resources that provide excellent descriptions on how to use the PropertyGrid.

Full Credit. As often happens it was while trolling through the newsgroups in search of a solution to the problem of how I was going to create an object at runtime, I came across a posting that described the world of PropertyDescriptorCollection and PropertyDescriptor classes. Thank you Venu Madhav ( for pointing me in the right direction. CustomClass in this application is adapted from Venu's CustomClass and there are notes in the application that describe the changes.

Using the code

To use the application - open the Visual Studio project and compile the application as a Windows Application - a .Exe file. Then change the project properties and Output Type to Class Library and compile again. This will create a .dll assembly. To use the Configuration Editor in your own Windows application - add a reference to the compiled .dll file and add the following two lines of codes to your application (under a menu called Settings for example). That's all there is to it. The application will attempt to find the .Config file if there is one present and automatically load it.

    private void mnuSettings_Click(object sender, System.EventArgs e)
        DotBits.Configuration.ConfigEditor c = new 

If you want to include the .Exe in your Setup Project as a Custom Action during installation simply include the ConfigEditor.Exe in the Setup Project as a required file. Create a Custom Action that points to the .Exe (and remember to change the Custom Actions InstallerClass property to false).

Note: There is a sample App.Config file in the project. You can run the project as soon as you unzip it to see what the application looks like - however you might be tricked into thinking that your changes to the .Config file are not being saved. Remember that Visual Studio will copy the App.Config file into the compiled directory every time the project is run - and so any setting changes you make while running the project will be lost when you run the project again.


Custom Configuration Sections and Handlers

Application Configuration Files Explained (Adventures in .NET)
Declaring Custom Configuration Sections (.NET Framework Developer's Guide)
Custom Element for NameValueSectionHandler and DictionarySectionHandler

The PropertyGrid Control

Getting the Most out of the .Net Framework PropertyGrid Control
Make your Components Really RAD with Visual Studio .Net Property Browser


  • First post 22 Feb 2004
  • Updated source code 2 Mar 2004<!------------------------------- That's it! --------------------------->


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Anthony Bouch
Web Developer
Thailand Thailand
I've been working in IT for about 14 years. Started in general support, networking and later specialized in publishing and editorial system networks.
Made the switch to full-time software development only about 5 years ago - mainly C#, VB and SQLServer. C# and ASP.Net for two years now and I love it.

Comments and Discussions

GeneralThanks PinmemberMember 450722329-Oct-14 8:27 
BugError while reading XML comments PinmemberAndreas Houben29-Nov-13 2:46 
GeneralMy vote of 5 PinmemberRonnieDean7719-Jun-13 7:01 
QuestionWhich license do you want? Pinmemberr.j.pieper27-Sep-12 12:04 
GeneralVS2005 exe.config file Pinmemberm_karahan18-Feb-10 5:00 
GeneralNew Version Pinmembertobster15-Sep-08 10:18 
GeneralRe: New Version Pinmemberkiquenet AE26-Dec-11 0:22 
GeneralEureka Pinmemberizmoto12-Mar-08 6:25 
GeneralChild nodes Pinmemberstub31-Aug-07 10:50 
GeneralRe: Child nodes Pinmembersebma29-Jul-10 1:55 
GeneralExcellent Example and References Pinmembergino_d_animal17-May-07 10:27 
GeneralMasking Pinmembertoshi_moshi1-Dec-06 2:37 
GeneralStoopid Pinmembervidapura20-Jan-06 7:35 
Questionstring[] ? PinmemberAlex........29-Oct-04 10:44 
GeneralProblem reading config file PinmemberShmulik2821-May-04 15:42 
GeneralSelect Different Editor PinmemberKevin Hartman4-Mar-04 10:06 
GeneralRe: Select Different Editor Pinmemberthomlemon11-May-04 10:18 
GeneralRe: Select Different Editor PinmemberAnthony Bouch11-May-04 20:22 
GeneralRe: Select Different Editor Pinmemberandang6-Jun-06 21:39 
GeneralRe: Select Different Editor PinmemberDutchMafia28-Feb-08 13:42 
Generalsections problem PinmemberJackDotNet29-Feb-04 3:59 
I tried to use the tool with real life config file that uses nested configSections and all I managed to see is just appSettings.
I simplified the file as in the example below and it looks like the same problem exists.
One level key/value settings update work just fine. Any ideas regarding "configSections"?
Config example:
<?xml version="1.0" encoding="Windows-1252"?><configuration> <configSections> <section name="DataPump" type="System.Configuration.NameValueSectionHandler, system, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=blahblah, Custom=null" /> </configSections> <appSettings> <add key="ApplicationName" value="DataPump" /> <add key="testparam" value="test value 2" /> </appSettings> <DataPump> <add key="DataPump key" value="DataPump value" /> </DataPump></configuration>
With deep respect,
GeneralRe: sections problem PinmemberAnthony Bouch29-Feb-04 4:19 
GeneralRe: sections problem PinmemberAnthony Bouch29-Feb-04 4:45 
GeneralRe: sections problem PinmemberJackDotNet29-Feb-04 12:29 
GeneralOops! Pinmembernetclectic23-Feb-04 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 2 Mar 2004
Article Copyright 2004 by Anthony Bouch
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid