Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Personally, I took Simon's answer and created an extension with it and added the Aspect Oriented Programming technique of declaring an expanded object using Attributes (you can add your flavor if you want, it's easy):</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace HQ.Util.WinFormUtil { public static class PropertyGridExtension { // ****************************************************************** public static void ExpandGroupName(this PropertyGrid propertyGrid, string groupName) { foreach (GridItem gridItem in propertyGrid.SelectedGridItem.GridItems) { if (gridItem != null) { if (gridItem.GridItemType == GridItemType.Category &amp;&amp; gridItem.Label == groupName) { gridItem.Expanded = true; } } } } // ****************************************************************** public static void ExpandItemWithInitialExpandedAttribute(this PropertyGrid propertyGrid) { ExpandItemWithInitialExpandedAttribute(propertyGrid, propertyGrid.SelectedGridItem); } // ****************************************************************** private static void ExpandItemWithInitialExpandedAttribute(PropertyGrid propertyGrid, GridItem gridItem) { if (gridItem != null) { if (gridItem.GridItemType == GridItemType.Property &amp;&amp; gridItem.Expandable) { object[] objs = gridItem.Value.GetType().GetCustomAttributes(typeof(PropertyGridInitialExpandedAttribute), false); if (objs.Length &gt; 0) { if (((PropertyGridInitialExpandedAttribute) objs[0]).InitialExpanded) { gridItem.Expanded = true; } } } foreach (GridItem childItem in gridItem.GridItems) { ExpandItemWithInitialExpandedAttribute(propertyGrid, childItem); } } } // ****************************************************************** } } </code></pre> <p>And this class</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HQ.Util.WinFormUtil { public class PropertyGridInitialExpandedAttribute : Attribute { public bool InitialExpanded { get; set; } public PropertyGridInitialExpandedAttribute(bool initialExpanded) { InitialExpanded = initialExpanded; } } } </code></pre> <p>And the usage is:</p> <pre><code>[PropertyGridInitialExpanded(true)] public class YourClass { ... } </code></pre> <p>And the call is:</p> <pre><code>this.propertyGrid.ExpandItemWithInitialExpandedAttribute(); </code></pre> <p>Happy coding ;-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload