Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi, is there a way to display an object of overrided abstract class in property grid?

For example, I have the following:
public abstract class Creature
    public string Height {get; set;}
    public string Weight {get; set;}

    public Creature();

public class Beast:Creature
    public string Species {get; set;}

    public Beast()

public class Human:Creature
    public string Name {get; set;}
    public Human() { }

I have a list of type Creature, and its objects are meant to be edited in property grid, but it shows only Height and Weight when I use
propertyGrid1.SelectedObject = creatures[i]

Is there a way, or should I just use (Beast) or (Human) before sending an object to property grid?

Also, is there a way this list can be serialized into XML?
Updated 21-Mar-11 11:31am
aidin Tajadod 21-Mar-11 19:22pm    
what heappen if you cast it?some thing like:
if (typeof (creatures[i] )==Human)

propertyGrid1.SelectedObject = (Human)creatures[i];

propertyGrid1.SelectedObject = (Beast)creatures[i];
dark13th 22-Mar-11 7:07am    
tried this but it wouldn't work:
if ((plist.Items[i]).GetType() == typeof(Human))
propertyGrid1.SelectedObject = (Human)plist.Items[i];
it still doesn't have Name in property grid.
Ian Good 21-Mar-11 21:26pm    
I tested this case in a new solution and had no problems (other than the compiler error for public Creature();).
What .Net version are you using?
dark13th 22-Mar-11 7:08am    
.NET 2.0

Well, on the clean solution it works without type casting, maybe it's my fault, thanks for your answers.
Also, found a solution for XML serializing here[^]
Share this answer
This is not how it is done.

See detailed instructions I gave answering a similar Question: How to get response when click PropertyGrid[^].

Custom presentation using property grid is quite feasible but not easy at all.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900