今天写个小程序,遇到一点小问题,最后还是处理好了(*^__^*) 嘻嘻
private void button1_Click(object sender, EventArgs e) { AddTreeNode(treeView1.Nodes, jiedianName, shuaxingwebst); }
/// <summary> /// 遍历所有节点(并且添加数据) /// </summary> /// <param name="tnodes">TreeNodeCollection</param> /// <param name="jiedianName">需要添加数据的节点名称</param> /// <param name="fenzuName">要添加的数据</param> private void AddTreeNode(TreeNodeCollection tnodes, string jiedianName, string fenzuName) { foreach (TreeNode node in tnodes) { if (node.Text == jiedianName.Trim()) { //给指定的节点增加子节点 node.Nodes.Add(fenzuName.Trim()); } AddTreeNode(node.Nodes, jiedianName, fenzuName); } }