WinForms PropertyGrid for C#/VB.NET

Edited by

10Tec iGrid control for WinForms is a cell matrix control, and it is generally used to create multi-column interfaces. But this grid can be used as a basis to implement an excellent WinForms PropertyGrid for C#/VB.NET application due to its rich set of features. Below is a screenshot of a C# PropertyGrid example:

WinForms PropertyGrid for C#/VB.NET example

We will compare iGrid.NET to the standard .NET PropertyGrid control and highlight some benefits of using iGrid as a property grid in the remainder of this article.

The standard WinForms PropertyGrid: pros and cons

As we all know, the intrinsic .NET PropertyGrid control provides a ready-to-use functionality one can use to browse all public properties of almost any .NET object. All you need to do is to assign a reference to the required object to the SelectedObject property of a PropertyGrid. The PropertyGrid scans all public properties of the object using the .NET reflection API and displays them automatically.

This is the main distinctive feature of the .NET PropertyGrid if we compare it to 10Tec iGrid.NET. In fact, iGrid is not a real PropertyGrid control that can display all public members of the specified .NET object automatically. When we talk about iGrid from this point of view, we mean the ability to create PropertyGrid-like interfaces.

For instance, it can be a settings interface when the user can view/set values for a set of properties. It is enough easy to start building of such an interface using the .NET PropertyGrid in C# or VB.NET application. Generally we implement a specialized object that contains the required properties and attach it to a PropertyGrid control. However, you can face a series of problems if you go this way. They occur because this PropertyGrid is a tool for a programmer but not an end-user. To find out more about these typical PropertyGrid problems and their solutions, you can read an article by Bob Powell Customizing properties for the PropertyGrid.

Benefits of iGrid.NET used as a WinForms PropertyGrid

In this section of the article we are focusing on some benefits of iGrid.NET used in VB or C# PropertyGrid-like solutions.

The stock PropertyGrid sorts its rows by property names (by the texts in the first column) in alphabetic ascending order. However, if we need another sort order, we need to implement a custom solution like in this article. But what if the user decides to sort by property values, i.e. by the texts in the second column? Or sort in descending order? It seems, there is no solution of this problem for the standard PropertyGrid. But in iGrid.NET, the user can sort our grid simply by clicking the column headers (or this ability can be provided in code by the developer if the column headers are hidden).

Another problem related to columns is the inability to resize the PropertyGrid columns from C# or VB.NET code. Sometimes we need to set a predefined column width proportion, or automatically adjust the width of the PropertyGrid value column to display the values without clipping. In iGrid, these operations are trivial.

Let's talk a little bit about customization of the .NET PropertyGrid interface. The first related thing we can think of is the ability to implement custom editors for property values. The stock WinForms PropertyGrid allows us to do that by writing our custom UI Type Editors (descendants of the System.Drawing.Design.UITypeEditor class). iGrid.NET also provides this functionality, but it is implemented much easier for such widely used editors like drop-down lists. The fact is that the 10Tec iGrid for WinForms package contains an additional drop-down list control intended for usage with iGrid (the iGDropDownList class), and we can harness it to implement this custom editor scenario. iGDropDownList allows you to create a list of required items optionally equipped with images very easy, and then you simply attach this drop-down list to an iGrid cell using its DropDownControl property. Below is a screenshot of such a custom PropertyGrid editor:

WinForms PropertyGrid drop-down list custom editor

Pay attention to the fact that the cell that represents the ForeColor property's value contains both the drop-down list button and the ellipsis button. In the standard WinForms PropertyGrid, you can have only either of them.

Needless to say that you can also use custom controls as drop-down editors due to the iGrid extensibility model:

WinForms PropertyGrid custom drop-down control editor

Another frequent problem developers encounter while creating customized interfaces based on the standard WinForms PropertyGrid is that it is impossible to change the background/foreground color and font of an individual cell that displays a property value. 10Tec iGrid can do this. You can observe that the value of the Font property on the very first picture in this article is drawn using the selected font that differs from the standard PropertyGrid font.

iGrid.NET provides one more interesting feature you can use in your C#/VB.NET PropertyGrid solutions. It's the custom scrollbar buttons feature. Perhaps, you have already noticed the two small buttons in the vertical scrollbar of the PropertyGrid on the first screenshot. In iGrid, you can add custom buttons to its scrollbars, and they can perform predefined or custom actions. In our C# PropertyGrid sample these custom scrollbar buttons are used to collapse and expand all categories in the PropertyGrid:

Customized scrollbar in a WinForms PropertyGrid C# solution


As you can see from this article, the WinForms PropertyGrid control for C#/VB.NET is good if you want to build a quick solution to browse properties of a .NET object. But this control may give you a lot of troubles if you try to use it as a basis for your customized PropertyGrid-like interface (and many of these problems can't be solved at all). If you need a customizable PropertyGrid control for a WinForms solution written in C# or VB.NET, 10Tec iGrid.NET with its rich capabilities is definitely worth your attention.

Visit the 10Tec iGrid for WinForms home page »