Edited by Martin Sutherland
10Tec iGrid.NET 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 an excellent substitution for C#/VB.NET PropertyGrid in WinForms applications due to its rich set of features. Below is a screenshot of a C# PropertyGrid example:
We will compare iGrid.NET to the standard .NET PropertyGrid control and highlight some benefits of using iGrid as a property grid control in C# or VB.NET in the remainder of this article.
The built-in 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 .NET objects. All you need to do is to assign a reference to the required object to the
SelectedObject property of a PropertyGrid in C#/VB.NET. 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 PropertyGrid control if we compare it to 10Tec iGrid. In fact, iGrid is not a true PropertyGrid control that can display all public members of the specified .NET object automatically. When we talk about iGrid in this context, we mean the ability to create PropertyGrid-like interfaces. For instance, it can be a settings interface in which the user can view/change values for a set of properties or parameters of something.
It is relatively easy to start building of such an interface using the .NET PropertyGrid in C# or VB.NET application. A well-known approach is to create a specialized object that implements the required properties and attach it to a PropertyGrid control. However, you can face a series of troubles if you go this way. Mainly they occur because the built-in .NET PropertyGrid control is a tool for a programmer but not an end-user, and to make it user-friendly you may need to write a lot of additional code. One of these tasks is implementing a custom editor in PropertyGrid (see this Customizing PropertyGrid example in C# at StackOverflow). If you are interested in a list of all available techniques you can use to customize PropertyGrid with examples in C# and VB.NET, read the following fundamental article at MSDN:
Benefits of iGrid.NET used instead of PropertyGrid in C# and VB.NET
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 one. 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 in C# or VB.NET. But in iGrid.NET, the user can sort the grid simply by clicking the required column headers (or this ability can be provided in code by the developer in the case if the column headers are hidden).
Another problem related to columns is the inability to resize the PropertyGrid columns from 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 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 drop-down list editor:
Pay attention to the fact that the cell displaying the value of the
ForeColor property 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, you can also use custom controls as drop-down editors due to the iGrid extensibility model:
One more 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. Pay attention to the value of the
Font property on the very first picture in this article - it 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 built-in or custom actions. In our C# PropertyGrid example these custom scrollbar buttons are used to collapse and expand all categories in the PropertyGrid:
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 C#/VB.NET WinForms applications, 10Tec iGrid.NET with its rich capabilities is definitely worth your attention.