1. 程式人生 > >c# winform propertygrid中的所有屬性直接展開不折疊

c# winform propertygrid中的所有屬性直接展開不折疊

如果要擴充套件網格中的所有專案,這非常簡單。屬性王個有一個方法:

properthGrid.ExpandAllGridItems();

如果要擴充套件特定的組,則可以使用此方法:

private static void ExpandGroup(PropertyGrid propertyGrid, string groupName)
{
    GridItem root = propertyGrid.SelectedGridItem;
    //Get the parent
    while (root.Parent != null)
        root = root.Parent;

    if
(root != null) { foreach (GridItem g in root.GridItems) { if (g.GridItemType == GridItemType.Category && g.Label == groupName) { g.Expanded = true; break; } } } }