Search code examples
c#winformspropertygrid

C# PropertyGrid - making all properties not bold


In a PropertyGrid form element, when I add properties to my categories, some appear in Bold.
Now, I know that it suggests that they are the default values in that category. My question is how to make all properties not bold?
I know one possible way is changing the DefaultValueAttribute attribute, but I was wondering if it can be done in a different way: this post suggests that I might have to use reflections, which is kind of mystical for me at the moment :)
Thank you in advance


Solution

  • For each property, you can add:

    private bool ShouldSerialize{PropertyName}() { return false; }
    

    Other than that, you are into the realm of custom PropertyDescriptor implementations via ICustomTypeDescriptor or TypeDescriptionProvider.

    Note that this pattern is used in a number of places, but in some (XmlSerializer, for example), it is required to be a public method.