代码之家  ›  专栏  ›  技术社区  ›  Not Sure

在PropertyGrid上设置SelectedTab

  •  2
  • Not Sure  · 技术社区  · 16 年前

    有人知道如何在.Net framework中以编程方式在PropertyGrid上设置选定的PropertyTab吗?SelectedTab属性不可设置,这是可以理解的,因为文档表明您不应该自己创建PropertyTab的实例。但是,我似乎找不到相应的方法来调用,也找不到要在PropertyGrid实例上设置的属性来更改代码中的选项卡,例如SelectTab(Type tabType)/int SelectedTabIndex{set;}。有什么想法吗?

    1 回复  |  直到 16 年前
        1
  •  2
  •   Not Sure    16 年前

        public int SelectedTabIndex 
        {
            set
            {
                Type pgType = typeof(PropertyGrid);
                BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
    
                ToolStripButton[] buttons = (ToolStripButton[]) pgType.GetField("viewTabButtons", flags).GetValue(this);
                pgType.GetMethod("SelectViewTabButton", flags).Invoke(this, new object[] { buttons[value], true });
            }
        }