List<A> aList和List<B> bListA和B各为实体类A
  -aName
  -aGroupB
  -bName
  -bGroup现在我想要遍历aList和bList,假如存在aOne.aGroup等于aTwo.aName,那么就将aOne归位aTwo的子节点。
同样,bOne.bGroup等于aOne.aName,将bOne归位aOne的子节点。TreeView结构为aTwo
   -aOne
      -bOne
请问大家如何递归最好给个简单的例子
C#TreeView集合合并

解决方案 »

  1.   

            public void initTree(List<MapLayerGroups> groupList, TreeNodeCollection treeNodeCollection, String parentName)
            {
                TreeNode newTreeNode;            for (int i = 0; i < groupList.Count; i++)
                {
                    String name = groupList[i].name;
                    if (parentName == null && groupList[i].group == "")
                    {
                        newTreeNode = new TreeNode(groupList[i].name);
                        treeNodeCollection.Add(newTreeNode);                    initTree(groupList, newTreeNode.Nodes, name);
                        newTreeNode.ExpandAll();                }
                    else if (groupList[i].group == parentName)
                    {
                        newTreeNode = new TreeNode(groupList[i].name);
                        treeNodeCollection.Add(newTreeNode);                    initTree(groupList, newTreeNode.Nodes, name);
                        newTreeNode.ExpandAll();
                    }
                }
            }这是我遍历一个List的情况,假如为group为空,那么就为父节点。我该如何改才把另一个List也给合并进去。。谢谢大家了。。