0

问题:

在下面的屏幕截图中,我有一个节点300-9885-00X及其 TreeNodeCollection(在红色方块中)。再低一点,我们又找到了300-9885-00X,我想将我们之前找到的 TreeNodeCollection 插入到那个节点中......

树视图节点


背景资料

我有一个遍历 AutoCAD / SolidEdge 程序集的递归程序。它打开文档并打印程序集及其子项,依此类推(递归)...

  • 绿色表示已打印
  • 橙色表示之前已经打印过,所以我们不需要再次打印...

问题:

我们如何将现有的 TreeNodeCollection插入到TreeNode中?

会心:

  1. TreeNodeCollection 的位置
  2. 我要将集合插入到的节点的位置

以下变量TreeNodes包含我的收藏。我必须遍历集合才能添加其文本吗? 树集合添加错误

4

2 回答 2

0

您不能将 a 添加TreeNodeCollection到节点。您必须遍历TreeNodeCollection单独添加节点,如下所示:

For j As Integer = 0 To TreeNodes.Count - 1
    n.Nodes.Add(TreeNodes(j).Clone())
Next

注意我使用了.Clone(). 这是由于插入了一个已经存在的节点。您不能这样做,您必须删除现有的或克隆它。就我而言,我必须克隆它。

于 2013-05-10T18:18:17.437 回答
0
// Get the '_NodesCollection' from the '_parentNode' TreeNode.
TreeNodeCollection _Nodes = _parentNode.FirstNode.Nodes;

// Create an array of 'TreeNodes'.
TreeNode[] Nodes = new TreeNode[_Nodes.Count];

// Copy the tree nodes to the 'Nodes' array.
_Nodes.CopyTo(Nodes, 0);

// Remove the First Node & Children from the ParentNode.
_parentNode.Nodes.Remove(_parentNode.FirstNode);

// Remove all the tree nodes from the '_parentNode' TreeView.
_parentNode.Nodes.Clear();

// Add the 'Nodes' Array to the '_parentNode' ParentNode.
_parentNode.Nodes.AddRange(Nodes);

// Add the Child Nodes to the TreeView Control
TvMap.Nodes.Add(_parentNode);
于 2015-08-22T20:25:13.607 回答