Search code examples
c#windowswinformspropertygrid

Can I change the displayed value of a category in a PropertyGrid (WinForm)?


Property names can be changed with

[Category("Application"), DisplayName("Application"), Description("Application settings")]

But can I get rid of the class name in a category? I wish to display my own "string" there. I have tried DisplayName etc (see example class below), but no change.

Any idea? Besides Application I wish to see some description.

Screenshot

Example classes:

public class CSettings
{
    [Category("Application"), DisplayName("Application"), Description("Application settings")]
    public CApplicationSettings Application { get; set; } = new CApplicationSettings();

    [Category("Audio"), Display(Name = "Audio", Description = "Audio settings")]
    public CAudioSettings Audio { get; set; } = new CAudioSettings();
}

As you can see, also tried to apply it on "class level"

[TypeConverter(typeof(ExpandableObjectConverter))]
[Description("Application general settings")]
[DisplayName("General settings")]
public class CApplicationSettings
{
    [Description("Application Hotkeys")]
    [DisplayName("Hotkeys")]
    public CHotkeyList Hotkeys { get; set; } = CHotkeyList.DefaultHotykeys;
}

Related


Solution

  • Credits/thanks to Simon Mourier and dr.null / Summary of their comments

    1. Override CApplicationSettings's ToString method or
    2. Create a custom TypeConverter (you can derive it from ExpandableObjectConverter), override ConvertTo, and return a string when destinationType == typeof(string). An example is the answer of Property Grid on composite objects here: https://stackoverflow.com/a/241942/356726