假如原先有5个节点,现在要添加几个新的节点,但是重复的不能添加。button1 添加abcde上去,button2添加2个数据 但是不能将重复的添加进去, 虽然很简单,但是感觉写的不错,分享给大家! 不知道的可以学习下,还有更好代码的可以分享下! 呵呵!
——————————————
TreeNode newNode1= treeView1.Nodes.Add("公司部门");
 public static string[] name1 = new string[5] { "a", "b", "c", "d" ,"e"};
        static bool a = true;
        private void button1_Click(object sender, EventArgs e)
        {
            if (a)
            {
                foreach (string s in name1)
                {
                    newNode1.Nodes.Add(s);
                }
                treeView1.ShowLines = true;
                treeView1.ShowPlusMinus = true;
                treeView1.ExpandAll();
                a = false;           
            }
        }
        static bool b = true;
        public static string[] name = new string[2] { "y", "d" };
        private void button2_Click(object sender, EventArgs e)
        {            if (b)
            {
                for (int i = 0; i < name.Length - 1; i++)
                {
                    foreach (TreeNode s1 in newNode1.Nodes)
                    {
                        if (s1.Text != name[i])
                        {
                            newNode1.Nodes.Add(name[i]);
                            break;
                        }
                    }
                }
                b = false;
            }
        }