Monday, 26 December 2011

How to find nodes on tree view and expand them


Place searchtextbox,Button on webform which contains Treeview



In the search button click event call this method


 private void FindInTreeView(TreeNodeCollection tncoll, string strNode)
       {
         foreach (TreeNode tnode in tncoll)
    {
        if (tnode.Text.ToLower() == strNode.ToLower())
        {
            tnode.Selected = true;
         
                tnode.Expand();
                tnode.ExpandAll();
                if (tnode.Selected == true)
                {
                    searchtextbox.Text = null;
                }
          
           
         
        }
        else
        {
            tnode.Selected = false;
          
          
        }
        FindInTreeView(tnode.ChildNodes,strNode);
    }

No comments:

Post a Comment