获取 treeView 的某些行并填充另一个 treeview

Get certain rows of a treeView and fill another treeview

如何在 c# syncfusion 中从 TreeView 中获取某些行及其所有子行并将它们填充到另一个 treeView 中?

谢谢

如果我理解您的意思并假设您正在从 WindowsForms TreeViews 复制节点,则以下代码可能会有所帮助:

    private void Form1_Load(object sender, EventArgs e)
    {
        MoveNodes(treeView1,treeView2,1, 2);
    }
    void AddRootNode(TreeView tree, TreeNode node)
    {
        var newNode = new TreeNode(node.Text);
        tree.Nodes.Add(newNode);
        foreach (TreeNode child in node.Nodes)
            AddChildNode(newNode, child);
    }
    void AddChildNode(TreeNode parent, TreeNode node)
    {
        var newNode = new TreeNode(node.Text);
        parent.Nodes.Add(newNode);
        foreach (TreeNode child in node.Nodes)
            AddChildNode(newNode, child);
    }
    private void MoveNodes(TreeView source,TreeView destination, params int[] indexes)
    {
        foreach (var index in indexes)
        {
            if (index < 0 || index >= source.Nodes.Count)
                continue;
            AddRootNode(destination, source.Nodes[index]);
        }
    }