Click here to Skip to main content
15,173,646 members
Articles / Programming Languages / C#
Posted 22 Feb 2004


118 bookmarked

Application Configuration Editor using the PropertyGrid

Rate me:
Please Sign up or sign in to vote.
4.80/5 (35 votes)
1 Mar 20045 min read
An application configuration editor using the PropertyGrid control.

Sample Image - configeditor.jpg


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


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 Pin
Member 450722329-Oct-14 8:27
MemberMember 450722329-Oct-14 8:27 
BugError while reading XML comments Pin
Andreas Houben29-Nov-13 2:46
MemberAndreas Houben29-Nov-13 2:46 
GeneralMy vote of 5 Pin
RonnieDean7719-Jun-13 7:01
MemberRonnieDean7719-Jun-13 7:01 
QuestionWhich license do you want? Pin
Ro4227-Sep-12 12:04
MemberRo4227-Sep-12 12:04 
GeneralVS2005 exe.config file Pin
Murat Karahan18-Feb-10 5:00
MemberMurat Karahan18-Feb-10 5:00 
GeneralNew Version Pin
tobster15-Sep-08 10:18
Membertobster15-Sep-08 10:18 
GeneralRe: New Version Pin
kiquenet.com26-Dec-11 0:22
professionalkiquenet.com26-Dec-11 0:22 
GeneralEureka Pin
izmoto12-Mar-08 6:25
Memberizmoto12-Mar-08 6:25 
GeneralChild nodes Pin
stub31-Aug-07 10:50
Memberstub31-Aug-07 10:50 
GeneralRe: Child nodes Pin
sebma29-Jul-10 1:55
Membersebma29-Jul-10 1:55 
GeneralExcellent Example and References Pin
gino_d_animal17-May-07 10:27
Membergino_d_animal17-May-07 10:27 
GeneralMasking Pin
toshi_moshi1-Dec-06 2:37
Membertoshi_moshi1-Dec-06 2:37 
GeneralStoopid Pin
vidapura20-Jan-06 7:35
Membervidapura20-Jan-06 7:35 
Questionstring[] ? Pin
Alex........29-Oct-04 10:44
MemberAlex........29-Oct-04 10:44 
GeneralProblem reading config file Pin
Shmulik2821-May-04 15:42
MemberShmulik2821-May-04 15:42 
GeneralSelect Different Editor Pin
Kevin Hartman4-Mar-04 10:06
MemberKevin Hartman4-Mar-04 10:06 
GeneralRe: Select Different Editor Pin
thomlemon11-May-04 10:18
Memberthomlemon11-May-04 10:18 
GeneralRe: Select Different Editor Pin
Anthony Bouch11-May-04 20:22
MemberAnthony Bouch11-May-04 20:22 
GeneralRe: Select Different Editor Pin
andang6-Jun-06 21:39
Memberandang6-Jun-06 21:39 
Generalsections problem Pin
JackDotNet29-Feb-04 3:59
MemberJackDotNet29-Feb-04 3:59 
GeneralRe: sections problem Pin
Anthony Bouch29-Feb-04 4:19
MemberAnthony Bouch29-Feb-04 4:19 
GeneralRe: sections problem Pin
Anthony Bouch29-Feb-04 4:45
MemberAnthony Bouch29-Feb-04 4:45 
GeneralRe: sections problem Pin
JackDotNet29-Feb-04 12:29
MemberJackDotNet29-Feb-04 12:29 
GeneralOops! Pin
netclectic23-Feb-04 3:25
Membernetclectic23-Feb-04 3:25 
GeneralRe: Oops! Pin
Anthony Bouch23-Feb-04 5:14
MemberAnthony Bouch23-Feb-04 5:14 

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

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