Results 1 to 3 of 3

Thread: Continue searching previous node?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Continue searching previous node?

    in a treeview, when I have searched all the current node's child nodes and when it finds an item it needs to find in the childnodes, how can i continue searching going back up one level and just carrying on?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Continue searching previous node?

    If you're searching using recursion then you don't have to do anything because you will continue with the next node inherently, e.g.
    CSharp Code:
    1. private void FindNodes(TreeNodeCollection nodes, string text)
    2. {
    3.     foreach (TreeNode node in nodes)
    4.     {
    5.         if (node.Text == text)
    6.         {
    7.             MessageBox.Show(node.FullPath, "Match Found");
    8.             this.FindNodes(node.Nodes, text);
    9.         }
    10.     }
    11. }
    Just call that method and pass the Nodes property of your TreeView to the first argument and it will recursively search the entire tree, popping up a message each time it encounters a node whose Text matches the specified value.
    Last edited by jmcilhinney; Nov 12th, 2007 at 06:05 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: Continue searching previous node?

    dear jmcilhinney,


    call FindNodes(Treeview1.nodes,"Server")

    is this correct ?
    Loving dotnet

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width