Advtree 通过NodeText 快速定位节点 使其选中

 

        public void FindSelectNode(string NodeText) //节点Text

        {

           foreach (Node tnc in Advtree1.Nodes) //遍历你的 treeView1     

           {

               nextnodes(tnc, NodeText); // 这个是你textBox1 中的文本     

           }

        }

        public void nextnodes(Node node, string text)  //遍历所有节点     

        {

            foreach (Node tn in node.Nodes)         

            {         

                if (tn.Text == text.Trim())    //判断节点的名称是否和你的treeview1中显示的Text值相等   

                {           

                   // tn.BackColor = Color.Red;     //改变查找的节点背景色         

                    showNodes(tn);

                    this.Advtree1.SelectedNode = tn;

                    //打开节点         

                }     

            }

            foreach (Node tn in node.Nodes)     

            {       

                nextnodes(tn,text);  //递归      

            }     

        }

        public void showNodes(Node node)   //打开节点   

        {    

            if (node != null)   

            {           

                node.Expand();     

                showNodes(node.Parent);

                //递归      

            }    

        }

 

你可能感兴趣的:(tree)