简体   繁体   English

C# 使用 TabControl 填充 TreeView

[英]C# Populating a TreeView with TabControl

So I've been able to populate a TreeView with the tabnames in WPF/XAML binding but haven't done this before with C# Windows Forms. So I've been able to populate a TreeView with the tabnames in WPF/XAML binding but haven't done this before with C# Windows Forms.

I want to have the treeview display the project name based on what file is open and then tabcontrol names below it (these are static -- one is called editor and the other fields).我想让 treeview 根据打开的文件显示项目名称,然后在其下方显示 tabcontrol 名称(这些是 static - 一个称为编辑器,其他字段)。

I'll add a context menu later, but the sole purpose would be to make the tabs visible based on their state with click events from the treeview.稍后我将添加一个上下文菜单,但唯一的目的是根据 state 和来自 treeview 的单击事件使选项卡可见。

My problem is I can't figure out how to associate them in the treeview.我的问题是我不知道如何在 treeview 中关联它们。 I found this code, can anyone tell me if I'm on the right track here?我找到了这段代码,谁能告诉我我是否走在正确的轨道上?

private void treeView1_AfterSelect(Object sender, TreeViewEventArgs e)
    {

        // Set the visibility of the tabpages from the treeview 
        if ((e.Action == TreeViewAction.ByMouse))
        {
            if (e.Node.Name == "Editor")
            {
                this.editForm.tabControl1.SelectedTab = editForm.Editor;
            }
            if (e.Node.Name == "Fields")
            {
                this.editForm.tabControl1.SelectedTab = editForm.Fields;
            }
        }
    }

You could use the TreeNodes's Tag property to hold the associated Tab Name.您可以使用 TreeNodes 的Tag 属性来保存关联的选项卡名称。

if (e.Action == TreeViewAction.ByMouse)
{
    TabPage p = tabControl1.TabPages[e.Node.Tag]
    tabControl1.SelectedTab = p;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM