This project has moved. For the latest updates, please go here.

PropertyGrid ExpandableObject with Expandableobject Childs cannot be expanded with an Expand method

Aug 30, 2012 at 8:49 AM

Hey Guys,

I am defining a three level(3X) nested property. It looks like:

class Property

{

[Category("A")]

[ExpandableObject]

public AudioSet Audio{  get{ return new AudioSet(); } }

}

class AudoiSet

{

[ExpandableObject]

public AudioProp Audio1{ get{return new AudioProp();} }

[ExpandableObject]

public AudioProp Audio2{ get{return new AudioProp();} }

}

class AudioProp

{

Prop1

Prop2

}

 

To expand my grid am using this method:

public void ExpandPropertyGrid()
{
            if (pgrProperties.Properties == null)
                return;

            foreach (var property in pgrProperties.Properties.Where(property => property.HasChildProperties))
            {
                if (property.HasChildProperties == true)
                {
                    property.IsExpanded = true;
                }
            }
}
Result: The Grid will expand the Property "Audio" so that i see "Audio1" and "Audio2", but it does not expand
"Audio1" and "Audio2" themselves to see "Prop1" and "Prop2". Reason is that my property grid object "pgrProperties" has only the following property by looking to it with QuickWatch:
"Audio".
What am I doing wrong? Am I defining the nested ExpandableObjects in a wrong way?
Thank you very much for your effort.
Hassan
Aug 30, 2012 at 5:18 PM

I've seen that the PropertyItem class has an "Properties" property that would contain the child objects to be displayed. Maybe try to set thoses property to "IsExpanded" too ?

Aug 31, 2012 at 7:01 AM
public void ExpandPropertyGrid()
{
            if (pgrProperties.Properties == null)
                return;

            foreach (var property in pgrProperties.Properties.Where(property => property.HasChildProperties))
            {
                property.IsExpanded = true;
                ExpandProperty(property);
            }
}

        public void ExpandProperty(PropertyItem property)
 {
            if (property.Properties == null)
                return;

            foreach (var element in property.Properties.Where(element => element.HasChildProperties))
            {
                element.IsExpanded = true;
                ExpandProperty(element);
            }
 }

Exactly this "Properties" object will always reference to null in case not expanded. So by expanding the first ExpandableObject, then the "Properties" will be filled with the child list, and from now on you can expand each child with the IsExpanded. Its now working :)

Thanks a lot