Sign in to follow this  

[.net] PropertyGrid - Nested Elements

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm pointing the PropertyGrid control at an object which has a number of properties. If the properties are of a type that has its own properties I'd like those properties to be visible too. If the property is of an existing type, such as a Button, then all the subproperties are displayed by expanding the item with its [+] sign. However, my custom types just appear with their .ToString() name, and aren't expandable to see the individual properties within. What does one need to do to make their custom times "expandable" when nested as properties in other types and viewed in a PropertyGrid?

Share this post


Link to post
Share on other sites
I am not quite sure whether you know about the custom type descriptor system, in case you don't there is this link here. I think the general idea is that you nest the type descriptions and hand it to the grid.

Hope that somehow helps,

Dave

Share this post


Link to post
Share on other sites
I'm sorry, I'm not sure what I should be looking for. [sad]

public class SomeClassWithProperties {
private string name;
public string Name {
get { return this.name; }
}
public override ToString() {
return "This doesn't work.";
}
}

public class TestClass {

private Button buttonProperty;
public Button ButtonProperty {
get { return this.buttonProperty; }
}

private SomeClassWithProperties someProperty;
public SomeClassWithProperties SomeProperty {
get { return this.someProperty; }
}

}

Let's say you created an instance of TestClass and viewed it in the PropertyGrid. It would list two properties. You could expand the ButtonProperty and see the properties exposed by Button fine, but you couldn't do anything with SomeProperty - it just displays "This doesn't work." and I'd like it to expand with a [+] and show the Name property, like it does for the Button's properties.

Thanks for the advice, though. [smile]

Share this post


Link to post
Share on other sites
You'd most likely be looking for the ExpandableObjectConverter

http://msdn2.microsoft.com/en-us/library/system.componentmodel.expandableobjectconverter.aspx

Alright a example


class PropertyGridClass
{
private ExpandableClass m_class;

public ExpandableClass Class {
get { return m_class; }
set { m_class = value; }
}
}

[TypeConverter(typeof(ExpandableObjectConverter))]
public class ExpandableClass
{
private string m_name;

public string Name
{
get { returm m_name; }
}
}

Share this post


Link to post
Share on other sites
Take a look at the DesignerSerializationVisibility attribute, specifically the Content value for the enumeration.

Actually, come to think of it, that only helps Visual Studio serialize your code properly. In order to get the expandability (word?), you need to add an ExpandableObjectConverter type converter to your class, like so:

[TypeConverter(typeof(ExpandableObjectConverter)]
public class Foo
{
}



That should do the trick.

I am not entirely sure that that is the right attribute you are looking for. There are so many that interact with the Visual Studio designer that I get confused so much. I am at work right now, but if that doesn't work and you can wait until I get home later, I can find out exactly using a great book I have that covers everything there is to know about providing design time support.

EDIT: Oops! Waaaay too slow.

Share this post


Link to post
Share on other sites

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this