字符串数组为
string [] str={"aa","bb_cc","bb_dd","cc_dd","cc_ff_gg"}
生成TREEVIEW结构是
aa
bb --cc
  |--dd
cc --dd
  |--ff
     |--gg
求生成算法

解决方案 »

  1.   

    添加根节点的方法如下,然后你再根据截取的字符串数组内容依次添加至根节点下 string existNode = "";
                int i;
                for (i = 0; i < str.Length; i++)
                {
                    string[] str1 = str[i].Split('_');
                    if (!existNode.Contains("|" + str1[0] + "|"))
                    {
                        existNode += "|" + str1[0] + "|";
                        TreeNode tr = new TreeNode(str1[0]);
                        AddNode(tr, dt,al);
                        this.TreeView1.Nodes.Add(tr);
                    }
                    
                }