简体   繁体   English

当需要动态调整多维清单时,我将使用什么?

[英]What would I use when in need of a dynamicly adjusting multidemnsional list?

I have a list that I want to function as a dynamically expanding tree-view, but if I am to have multiple lists inside of a list I need to declare that in the initial list's definition. 我有一个想要用作动态扩展树视图的列表,但是如果要在列表中包含多个列表,则需要在初始列表的定义中声明它。 What am I missing to accomplish this and is there something better to use to accomplish my goal? 我缺少实现这一目标的东西,还有没有更好的东西可以用来实现我的目标?

For the sake of context: I am trying to populate it like a tree view so that I may replicate the registry within my application. 出于上下文考虑:我试图像树视图一样填充它,以便可以在应用程序中复制注册表。

Use the correct type for your scenario. 为您的方案使用正确的类型。

In your case, this is a class TreeNode like so: 在您的情况下,这是一个类似TreeNode类,如下所示:

public class TreeNode
{
    private readonly List<TreeNode> _children = new List<TreeNode>();

    public TreeNode(string name, params TreeNode[] children)
    {
        Name = name;
        _children.AddRange(children);
    }

    public List<TreeNode> Children { get { return _children; } }
    public string Name { get; set; }
}

Assume the following tree: 假设以下树:

Root
+ Child1
  + Child1a
  + Child1b
+ Child2
  + Child2a
    + Child2aA
    + Child2aB
  + Child2b

You would create it like so: 您可以这样创建它:

var root = new TreeNode("Root",
                        new TreeNode("Child1",
                                     new TreeNode("Child1a"),
                                     new TreeNode("Child1b")),
                        new TreeNode("Child2",
                                     new TreeNode("Child2a",
                                                  new TreeNode("Child2aA"),
                                                  new TreeNode("Child2aB")),
                                     new TreeNode("Child2b")));

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

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