这里假定只有两级节点,多级方法类似。
遍历节点,根据选中节点文本找到要选中的节点。
treeView.SelectedNode
= selectNode;
/// <summary> /// 设置TreeView选中节点 /// </summary> /// <param name="treeView"></param> /// <param name="selectStr">选中节点文本</param> private void SelectTreeView(TreeView treeView, string selectStr) { treeView.Focus(); for (int i = 0; i < treeView.Nodes.Count; i++) { for (int j = 0; j < treeView.Nodes[i].Nodes.Count; j++) { if (treeView.Nodes[i].Nodes[j].Text == selectStr) { treeView1.SelectedNode = treeView.Nodes[i].Nodes[j];//选中 //treeView.Nodes[i].Nodes[j].Checked = true; treeView.Nodes[i].Expand();//展开父级 return; } } } }
转:http://greatverve.cnblogs.com/archive/2012/02/07/treeview-selectednode.html