Mircea Ispas
Mircea Ispas

Reputation: 20780

PropertyGrid does not list member class members

I have:


class Foo1
{
    private string name1;
    [CategoryAttribute("Category1")]
    public string Name1
    {
        get { return name1; }
        set { name1 = value; }
    }
}

and


class Foo2
{
    private string name2;
    [CategoryAttribute("Category2")]
    public string Name2
    {
        get { return name2; }
        set { name2 = value; }
    }
}

If I have Foo2 derived from Foo1 and set Foo2 as SelectedObject in a PropertyGrid, I will have members of Foo1 listed, but if I have Foo1 member in Foo2, Foo1 members are not listed. Is there any way to list members of Foo1 in the PropertyGrid for the second case?

Thanks!

Upvotes: 2

Views: 1405

Answers (2)

pdiddy
pdiddy

Reputation: 6297

you need typeconverter to achieve this. Take a look at this : Getting the Most Out of the .NET Framework PropertyGrid Control at section Support for Custom Types

Upvotes: 1

EgorBo
EgorBo

Reputation: 6142

try to specify a typeconverter for Foo2. Now Foo2's members should be listed in Foo1 object's property.

[TypeConverter(typeof(ExpandableObjectConverter))]
class Foo2
{
    private string name2;
    [CategoryAttribute("Category2")]
    public string Name2
    {
        get { return name2; }
        set { name2 = value; }
    }
}

Upvotes: 3

Related Questions