/// <Summary> /// set the node to be searched as the selected node /// tu juwen /// 2013-07-15 /// </summary> /// <param name =" trvToSrch "> </param> // <param name =" strToSrch "> </param> // <returns> </returns> public TreeNode srchTxtInSelectTreeView (TreeView trvToSrch, string strToSrch) {// check if the treeView is not NULL if (trvToSrch = null) return null; // loop through the nodes in the treeview's root nodes for (int I = 0; I <trvToS Rch. Nodes. Count; I ++) {TreeNode trvNode = srchTxtInSelectTreeViewNode (trvToSrch. Nodes [I], strToSrch); if (trvNode! = Null) return trvNode;} return null ;} /// <summary> /// find a node /// </summary> /// <param name = "trvNode"> </param> /// <param name = "strToSrch"> </param> // <returns> </returns> public TreeNode srchTxtInSelectTreeViewNode (TreeNode trvNode, string strToSrch) {// check if the treeView is not NULL if (trvNode = null) return null; if (trvNode. text = strToSrch) return trvNode; // loop through the nodes In the treeview's sub nodes for (int I = 0; I <trvNode. nodes. count; I ++) {// recursive call to itself to check lower level nodes TreeNode retTrvNode = srchTxtInSelectTreeViewNode (trvNode. nodes [I], strToSrch); if (retTrvNode! = Null) return retTrvNode;} return null ;}
// TreeView initialization settings default selection node treeView1.SelectedNode = srchTxtInSelectTreeView (treeView1, "Shenzhen ");