Can we change the text/background color of an individual property in PropertyGrid
Asked Answered
A

1

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?
Arruda answered 18/5, 2010 at 13:20 Comment(0)
M
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.

Mol answered 18/5, 2010 at 14:35 Comment(2)
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.NonPublicArruda
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?Gringo

© 2022 - 2024 — McMap. All rights reserved.