Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?
like image 895
Charvak Avatar asked May 18 '10 13:05

Charvak


1 Answers

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.

like image 187
Hans Passant Avatar answered Nov 03 '22 05:11

Hans Passant