Two issues with PropertyGrid -

Grids for WPF Forum

Posted 15 years ago by Gerald Kelly
Version: 9.1.0507
Two issues that I'm having that I can't seem to find a solution to.

1. If you have a an object A that contains object B and object B has say two public string properties. The PropertyGrid just shows the type of B rather than the contents of B. I have not seen any PropertyGrid property that states whether to allow for this or not.

2. I want to be able to set the DisplayName attribute at run time since this will depend on the language selected. So, what I did was create a derived class:

public class DisplayName2 : System.ComponentModel.DisplayNameAttribute
public DisplayName2()

public DisplayName2(string p_DisplayName)
DisplayNameValue = p_DisplayName;

public string RealDisplayName
get { return this.DisplayNameValue; }
set { this.DisplayNameValue = value; }

I can use it this way...

class Whatever {
public string Name { get; set; }

then in code I would change this if necessary like this..

var v_Attr = typeof(Whatever).GetProperty("Name").GetCustomAttributes(false)[0] as DisplayName2;
v_Attr.RealDisplayName = "ChangedName";

or this way...

var v_Type = typeof(Whatever);
var v_FieldInfo = v_Type.GetProperty("Name");
var v_Attr = Attribute.GetCustomAttribute(v_FieldInfo, typeof(DisplayName2)) as DisplayName2;
v_Attr.RealDisplayName = "ChangedName";

either way, when the PropertyGrid is displayed, it shows, in the first column, "InitialName" instead of "ChangedName"

What is interesting is that I downloaded different PropertyGrid from a competitor to see what it did. It did the same thing.
How do I solve this problem?

Comments (1)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Gerald,

1. Properties displayed by our PropertyGrid (and the native WinForms PropertyGrid) are not expandable by default. You must implement a TypeConverter that indicates the given property should be expandable. Luckily, .Net provides a default TypeConverter you can use that makes an object expandable, called ExpandableObjectConverter. If you look at the Lazy Loading QuickStart under the PropertyGrid section of our Sample Browser you can see how it's used.

2. Eventhough you changed the underlying display name there is nothing that notifies the PropertryGrid that it changed. You would need to call Refresh() on the PropertyGrid, to force it to update and pull the new display name value.

It would be possible to dynamically change the display name dynamically, but that would required you to implement a custom IPropertyDataAccessor (which is part of our PropertyGrid's data layer). Our default implementations simply look for the DisplayNameAttribute, but you could have your custom implementation look else where and raise the PropertyChanged event to notify the PropertyGrid of the changes. If this is something you would like to do let us know.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.