本文介绍了展开显示的C#propertygrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对物业表格有疑问.当显示表单时,我希望将一组展开而不是折叠.我在网上搜索了很多东西,但还找不到.任何想法.

i have a question about property grid.when the form is shown i would like a group to be expand rather then collapsed.i have search a lot for that on the web and could not find it yet.any thoughts.

推荐答案

如果要扩展网格中的所有项目,这非常简单.属性网格具有一种用于执行此操作的方法:

If you want to expand all items in the grid it is fairly simple. The property grid has a method for doing that:

propertyGrid.ExpandAllGridItems();

如果您要扩展某个组,则可以使用此方法:

If it is a certain group you want to expand you can use this method:

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;
            }
        }
    }
}

这篇关于展开显示的C#propertygrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 16:20