6

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?
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Charvak
  • 289
  • 2
  • 13

1 Answers1

9

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
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 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 May 18 '10 at 18:40
  • 1
    Not sure whether I do understand the very first sentence "No can do." correctly. Being a non-native English speaker, I would have thought, that it should read "No can't do.". Am I missing something? – Uwe Keim Jun 07 '18 at 10:33