默认的每个分类下的属性都是展开的
因为属性过多
所以默认的情况下,不让某个分类展开
这个怎么实现
谢谢各位

解决方案 »

  1.   


        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                this.propertyGrid1.SelectedObject = this;
                ExpandFirstCategoryOnly();
            }        private void ExpandFirstCategoryOnly()
            {
                this.propertyGrid1.CollapseAllGridItems();            GridItemCollection gridItems = GetGridItems(this.propertyGrid1);
                if( gridItems.Count > 0 )
                {
                    gridItems[0].Expanded = true;
                }
            }        private static GridItemCollection GetGridItems(PropertyGrid grid)
            {
                GridItemCollection result = typeof(PropertyGrid).InvokeMember(
                    "GetPropEntries",
                    BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
                    null, grid, new object[] { }
                    ) as GridItemCollection;            return result ?? GridItemCollection.Empty;
            }
        }