Click here to Skip to main content
14,578,799 members

PropertyGrid utilities

Rate this:
4.90 (40 votes)
Please Sign up or sign in to vote.
4.90 (40 votes)
7 Jan 2016CPOL
An article on sorting and globalization of properties in a PropertyGrid.

Image 1

Image 2


This article is on sorting and globalization of properties in a PropertyGrid.


  • Declarative (static) definition of property behaviour: property order, DisplayName, globalization of DisplayName, Description, and Category.
  • Dynamic definition of property behaviour using a call back. For each property, a property attributes provider can be set in which all attributes mentioned above can be overridden. Also, IsBrowsable and IsReadOnly can be modified at runtime.
  • Use the Tab key for tabbing through items.
  • Globalized tool tips of tool bar buttons.

It's easy to use and has ways to modify the place it looks for resources.


I ripped code from two projects, fused and improved them. The sorting idea was ripped from Paul Tingey, his PropertySorter class. Globalization was ripped from Globalized Property Grid by Gerd Klevesaat. He, however, used inheritance from GlobalizationObject, which makes the mechanism not so flexible. Plus, his implementation was very slow (especially in combination with sorting), and didn't include Category globalization. The dynamic behaviour was developed by George Soules and me.

Using the code

The example below basically shows most of the possibilities:

using System;
using System.ComponentModel;

using PropertyGridUtils;

namespace MyNameSpace
    class SomeClassWithProperties {
        string lastName = "Zeeuw";
        string occupation = "Software engineer";

        int dynamicProperty = 3;
        string dynamicPropertyDisplayName = "Dynamic property";
        bool dynamicPropertyIsVisible = true;
        bool dynamicPropertyIsReadOnly = false;

        string propertyWithResourcesElseWhere = "Dummy";
        SomeClassWithProperties child;

        // DisplayName and Description are gotten from resource file
        // MyNameSpace.SomeClassWithProperties.resources.
        [GlobalizedProperty(CategoryId = "GlobalCategory")]
        public string LastName {
            get {
                return lastName;

        // DisplayName and Description are gotten from resource file
        // MyNameSpace.SomeClassWithProperties.resources.
        [GlobalizedProperty(CategoryId = "GlobalCategory")]
        public string Occupation {
            get {
                return occupation;

        // Behaviour of this property is partially defined runtime.
        [Description("This property is partially dynamic.")]
        public int DynamicProperty {
            get {
                return dynamicProperty;
            set {
                dynamicProperty = value;

        public void DynamicPropertyAttributesProvider(PropertyAttributes attributes) {
            attributes.DisplayName = dynamicPropertyDisplayName;
            attributes.IsReadOnly = dynamicPropertyIsReadOnly;
            attributes.IsBrowsable = dynamicPropertyIsVisible;

        [DisplayName("Dynamic property display name")]
        public string DynamicPropertyDisplayName {
            get {
                return dynamicPropertyDisplayName;
            set {
                dynamicPropertyDisplayName = value;

        [DisplayName("Dynamic property visible")]
        public bool DynamicPropertyIsVisible {
            get {
                return dynamicPropertyIsVisible;
            set {
                dynamicPropertyIsVisible = value;

        [DisplayName("Dynamic property readonly")]
        public bool DynamicPropertyIsReadOnly {
            get {
                return dynamicPropertyIsReadOnly;
            set {
                dynamicPropertyIsReadOnly = value;

        // DisplayName and Description are gotten from resource file
        // SomeOtherResources.resources
                            BaseName = "SomeOtherResources",
                            DisplayNameId = "Dummy.DisplayName",
                            DescriptionId = "Dummy.Description"
        public string PropertyWithResourcesElseWhere {
            get {
                return propertyWithResourcesElseWhere;

        // Property with sub properties for testing
        // tabbing accross expanded/non expanded items.
        public SomeClassWithProperties Child {
            get {
                if (child == null) {
                    child = new SomeClassWithProperties();
                return child;

Static usage

Property behaviour is defined using the attributes DisplayNameAttribute, DescriptionAttribute, GlobalizedPropertyAttribute, GlobalizedTypeAttribute, and PropertyOrderAttribute.

Usage without resources is simple, users can use the DisplayNameAttribute and DescriptionAttribute to directly set the DisplayName and Description. But when working like this, the properties are not globalized.

Using resource files enables globalization, but is slightly more complicated. By default, resources are gotten from a file namespace.class.resources. This can, if needed, be controlled with the GlobalizedPropertyAttribute or GlobalizedTypeAttribute. The resource for DisplayName is gotten from the ResourceManager from the resource string SomeProperty.DisplayName. Similarly, the Description is gotten from SomeProperty.Description. This can also be controlled through the GlobalizedPropertyAttribute though, so, e.g., description strings can be reused in multiple properties/classes. Category is, by default, gotten from SomeProperty.Category. To reuse a category string in a resource file, you can specify [GlobalizedProperty(CategoryId = "GlobalCategory")] (thanks to Paul Tingey for the idea).

Dynamic usage

It is possible to define a PropertyAttributesProviderAttribute at a property. The method name mentioned there will be called by the PropertiesDeluxeTypeConverter with a PropertyAttributes object as the only parameter. The method can then change all attributes there, like IsBrowsable, IsReadOnly, DisplayName, etc. The PropertyGrid must be refreshed (Refresh()) for the changes to take effect.

Tabbing through properties

To make use of the Tab key feature and globalized tool tips for the tool bar buttons, use CustomPropertyGrid. It also has a property ExpandOnTab which sets whether to expand an expandable item when tab is pressed. Note that pressing the Enter key also achieves that.

Points of interest

If no resource file is there for the neutral culture, globalization is disabled. But still, PropertiesDeluxeTypeConverter can then be used for sorting and setting the DisplayName of properties.

One could set up the resources to, e.g., use only one resource file. There is no protection from name clashes then though. The namespace could be prepended to the resource names, but then the names would get very long.

For adding languages for the tool tips, compile satellite assemblies containing the PropertyGridUtils.CustomPropertyGrid.<language>.resources file (don't forget signing and giving it the correct assembly version, see PropertyGridUtils\compileResources.bat). The assembly must be located in a <language> subdir, like the nl example.

New status bar class (.NET 1.1 only)

I also wrote a small status bar class because the standard .NET 1.1 status bar doesn't allow embedding of controls (the .NET 2.0 StatusStrip is more powerful). It's not much code so it's probably not worth devoting a separate article to it (and there's already one somewhere on CodeProject doing something similar). One feature that is in this version that I like is that both absolute and relative widths can be mixed in the status bar items. E.g., two items can be defined, one of absolute width 50 pixels, relative width 70%, and the other item 200 pixels, relative width 30%. If the total status bar width is 1000 pixels, then 200 + 50 = 250 pixels are fixed. The remaining 750 pixels are divided according to the relative sizes.


  • 7 April 2006, migrated to .NET 2.0 (DisplayNameAttribute is now part of the .NET libraries).
  • 21 June 2005, improved tabbing to go over all expanded items instead of items on one level ( Also added a new status bar class.
  • 19 October 2004, cooperated with George Soules to add dynamic behaviour. (Assembly version is now
  • 12 September 2004, added Tab key feature and globalized tool tips for tool bar buttons.
  • 21 July 2004, first version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

wout de zeeuw
Software Developer (Senior)
Netherlands Netherlands
Wout works as a freelancer based in the Netherlands. His interests are .NET, 3D, DWG, DXF, OpenGL, Computational Geometry and playing Tank Ball!

One of his latest private projects is a commercial DWG DXF .NET library and small DWG DXF viewing application.

Comments and Discussions

QuestionSplitter position Pin
Zek Patafta16-Oct-16 18:21
MemberZek Patafta16-Oct-16 18:21 
QuestionHow to display DisplayName and Description in SomeOtherResource.resources Pin
Member 125017808-Jul-16 3:53
MemberMember 125017808-Jul-16 3:53 
GeneralMy vote of 5 Pin
Code Artist20-Apr-16 3:53
professionalCode Artist20-Apr-16 3:53 
QuestionProblem getting it to work in my app Pin
Karrok8-Mar-16 1:23
MemberKarrok8-Mar-16 1:23 
AnswerRe: Problem getting it to work in my app Pin
wout de zeeuw8-Mar-16 3:12
Memberwout de zeeuw8-Mar-16 3:12 
QuestionLicense Pin
BMW74012-Jul-12 23:11
MemberBMW74012-Jul-12 23:11 
GeneralMy vote of 5 Pin
cdinten11-Jun-12 3:10
Membercdinten11-Jun-12 3:10 
GeneralRe: My vote of 5 Pin
wout de zeeuw19-Jun-12 4:31
Memberwout de zeeuw19-Jun-12 4:31 
GeneralFinally Pin
LW0027-Jan-10 4:40
MemberLW0027-Jan-10 4:40 
GeneralRe: Finally Pin
wout de zeeuw27-Jan-10 5:05
Memberwout de zeeuw27-Jan-10 5:05 
GeneralTab! Tab! Tab! Pin
Ryan McFarren20-Mar-09 10:48
MemberRyan McFarren20-Mar-09 10:48 
GeneralRe: Tab! Tab! Tab! Pin
wout de zeeuw20-Mar-09 17:42
Memberwout de zeeuw20-Mar-09 17:42 
GeneralRe: Tab! Tab! Tab! Pin
D. de Kerf10-Nov-14 1:35
MemberD. de Kerf10-Nov-14 1:35 
GeneralNew solution with greater flexibility Pin
Mizan Rahman22-Feb-09 4:12
MemberMizan Rahman22-Feb-09 4:12 
QuestionHow do I use the Enter key for tabbing through items. Pin
Paresh B Joshi16-May-08 7:26
MemberParesh B Joshi16-May-08 7:26 
AnswerRe: How do I use the Enter key for tabbing through items. Pin
xiwang10-Oct-08 0:42
Memberxiwang10-Oct-08 0:42 
GeneralRe: How do I use the Enter key for tabbing through items. Pin
Paresh B Joshi13-Oct-08 4:26
MemberParesh B Joshi13-Oct-08 4:26 
GeneralDisplay collections as child nodes Pin
Len202025-Feb-08 9:53
MemberLen202025-Feb-08 9:53 
GeneralFantastic Pin
Angelus1234519-Jul-07 1:23
MemberAngelus1234519-Jul-07 1:23 
GeneralRe: Fantastic Pin
wout de zeeuw19-Jul-07 1:59
Memberwout de zeeuw19-Jul-07 1:59 
GeneralGreat Pin
mileni21-Mar-07 23:31
Membermileni21-Mar-07 23:31 
GeneralRe: Great Pin
wout de zeeuw30-May-07 3:10
Memberwout de zeeuw30-May-07 3:10 
GeneralRemoving Properties inherited from PictureBox Pin
khoonseng13-Dec-06 19:56
Memberkhoonseng13-Dec-06 19:56 
GeneralProperty sorting in VS2005 c++ Pin
khoonseng13-Dec-06 19:43
Memberkhoonseng13-Dec-06 19:43 
GeneralRe: Property sorting in VS2005 c++ Pin
elfi1221-Aug-07 5:23
Memberelfi1221-Aug-07 5:23 

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.

Posted 7 Jan 2016


149 bookmarked