Лично я взял ответ Саймона, создал с ним расширение и добавил технику Аспектно-ориентированного программирования для объявления расширенного объекта с помощью атрибутов (вы можете добавить свой аромат, если хотите, это просто):
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 && 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 && gridItem.Expandable)
{
object[] objs = gridItem.Value.GetType().GetCustomAttributes(typeof(PropertyGridInitialExpandedAttribute), false);
if (objs.Length > 0)
{
if (((PropertyGridInitialExpandedAttribute) objs[0]).InitialExpanded)
{
gridItem.Expanded = true;
}
}
}
foreach (GridItem childItem in gridItem.GridItems)
{
ExpandItemWithInitialExpandedAttribute(propertyGrid, childItem);
}
}
}
// ******************************************************************
}
}
И этот класс
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;
}
}
}
И использование:
[PropertyGridInitialExpanded(true)]
public class YourClass
{
...
}
И звонок:
this.propertyGrid.ExpandItemWithInitialExpandedAttribute();
Счастливого кодирования; -)