0

我想在 TreeView 中添加一个表。这可能吗?这是我用来生成 TreeView 的以下 C# 代码:

        var items = tree1.Items;

        var item = new TreeViewItem() { Header = "End Item 1" };
        items.Add(item);

        var assemblies = new TreeViewItem() { Header = "Assemblies" };
        var endpart = new TreeViewItem() { Header = "Parts" };

        foreach (TreeViewItem n in items)
        {

            /// ASSEMBLIES
            (n as TreeViewItem).Items.Add(assemblies);
            /// ASSEMBLIES - ASSEMBLY 1
            var subass = new TreeViewItem() { Header = "Assembly 1" };
            foreach (TreeViewItem o in (n as TreeViewItem).Items)
            {
                if (o.Header == "Assemblies")
                {
                    (o as TreeViewItem).Items.Add(subass);
                    // TABLE of PARTS


                }

            }

            ///PARTS
            (n as TreeViewItem).Items.Add(endpart);

            ///PARTS - PART1
            var subendpart = new TreeViewItem() { Header = "Part1" };
            foreach (TreeViewItem p in (n as TreeViewItem).Items)
            {
                if (p.Header == "Parts")
                    (p as TreeViewItem).Items.Add(subendpart);
            }


        }

    }

我想检索有关每个部分的数据并将其包含在 Part 标题下的表格中。我该怎么办?

4

0 回答 0