这里假定只有两级节点,多级方法类似。
遍历节点,根据选中节点文本找到要选中的节点。
treeView.SelectedNode = selectNode;
1 /// <summary> 2 /// 设置TreeView选中节点 3 /// </summary> 4 /// <param name="treeView"></param> 5 /// <param name="selectStr">选中节点文本</param> 6 private void SelectTreeView(TreeView treeView, string selectStr) 7 { 8 treeView.Focus(); 9 for (int i = 0; i < treeView.Nodes.Count; i++) 10 { 11 for (int j = 0; j < treeView.Nodes[i].Nodes.Count; j++) 12 { 13 if (treeView.Nodes[i].Nodes[j].Text == selectStr) 14 { 15 treeView1.SelectedNode = treeView.Nodes[i].Nodes[j];//选中 16 //treeView.Nodes[i].Nodes[j].Checked = true; 17 treeView.Nodes[i].Expand();//展开父级 18 return; 19 } 20 } 21 } 22 }
http://greatverve.cnblogs.com/archive/2012/02/07/treeview-selectednode.html