views:

119

answers:

1

I have a .NET PropertyGrid control which displays properties of some class. I want to change the color or font or background color(it doesn't matter just that they look different from the other displayed properties) of some property. I can do with writing custom editor but I was wondering

  1. If an easier method exists?
  2. If I use custom editor then how do i change the editor of built-in types like bool, int etc.

Thanks

+1  A: 

No can do. The class that determines how an item is drawn is PropertyGridView. The source code is interesting, it almost made it:

    private /*protected virtual*/ PropertyGridView CreateGridView(IServiceProvider sp) {
        return new PropertyGridView(sp, this);
    }

Nope, looks like at the last minute they decided against making the method overridable. The PropertyGridView class was also marked internal. Replacing all this code (there is a lot of it) is not a realistic option.

Creating your own UITypeEditor for built-in types is only possible by applying the [Editor] attribute to the properties in the class you want to edit. That's not a general solution. Consider creating your own form to make the object editable instead.

Hans Passant
Is there a way to change the property name instead. I would like to add "*" before the name to indicate the difference for example "*Font" instead of "Font". I tried with reflection but displayName field is shown in the debugger which when change works however I am unable to get the field from reflection.I am using proper binding flags ie BindingFlags.NonPublic
Charvak