Configure the PropertyGrid Control
Friday, July 20th, 2007Exam objective: 70-526 - Configure the PropertyGrid component
The .NET Framework contains a fairly complete selection of controls and form components that allow information to be input, presented and changed in many different ways. In this article I will cover one of the more complex but also feature-rich components in the .NET framework: the PropertyGrid. Regardless of whether you have experience with the using the PropertyGrid in your own apps, if you used Visual Studio, you already used the PropertyGrid component many times. Visual Studio uses several PropertyGrid components in its main interface, the most obvious being the Properties and Events windows, highlighted in the screenshot below:
So setting the Properties of a Form or control for example is done by using a PropertyGrid and as you can see, it is very complete. It allows you to set a wide variety of Property types such as Booleans, Strings, Integers, Fonts, Point and Size structures, Colors, Images, Enums, and Collections without the need for complex code. Additionally, the PropertyGrid component can be extended to support additional custom property types and to customize the GUI of the properties in the PropertyGrid.
The PropertyGrid is particularly useful when you have a good amount of different properties that need to be set or displayed in the proper format. If you would use a combination of labels, textboxes, radio buttons, checkboxes, etc. you would have to create many different controls and write input validation code. That doesn’t mean a PropertyGrid is always a better alternative, a form with the classic form components works best for most applications as users are familiar with it.
Throughout the rest of this article we’re going to create an example project that shows you how little effort it takes to add a working PropertyGrid to a Form. After going over some basic properties of the PropertyGrid itself, we’ll cover its implementation in more detail. I assume you have some basic experience with Visual Studio and setting control properties using the GUI.


