Search code examples
c#wpfpropertygrid

Displaying custom name instead of class type in WPF propertygrid


Check out the following link in WPF PropertyGrid documentation. In the image of property grid, notice that the text displayed next to Spouse is

Samples.Modules.PropertyGrid.Views.ExpandableProp

That doesn't look good when you are exposing a PropertyGrid to customers. How can I customize what I display there? Please note that TypeConverter doesn't work for WPF PropertyGrid. I have already tried that :)


Solution

  • Just override the ToString() method of Person class and return whatever you want.

    In the below code it returns the first name. With this change it displays the first name of the Spouse instead of Samples.Modules.PropertyGrid.Views.ExpandableProp

    public override string ToString()
    {
        return FirstName;
    }