Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Go to a specified node in treeview

Go to a specified node in treeview

Scheduled Pinned Locked Moved C#
question
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Laji59
    wrote on last edited by
    #1

    I want to go to a specified node in TreeView. How can I do it?

    Hello Friends

    R K 2 Replies Last reply
    0
    • L Laji59

      I want to go to a specified node in TreeView. How can I do it?

      Hello Friends

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Locate the node using the control's Nodes property. Then set the control's SelectedNode property. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      L 1 Reply Last reply
      0
      • R Ravi Bhavnani

        Locate the node using the control's Nodes property. Then set the control's SelectedNode property. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        L Offline
        L Offline
        Laji59
        wrote on last edited by
        #3

        Thanks But can you make a sample for me in one line code? Thanks in advanced

        Hello Friends

        R 1 Reply Last reply
        0
        • L Laji59

          Thanks But can you make a sample for me in one line code? Thanks in advanced

          Hello Friends

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          No. But, I'll be more than happy to help if you have a specific question after trying to do this yourself. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          L 2 Replies Last reply
          0
          • R Ravi Bhavnani

            No. But, I'll be more than happy to help if you have a specific question after trying to do this yourself. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            L Offline
            L Offline
            Laji59
            wrote on last edited by
            #5

            I tried this way for many time but I couldn`t get ane success Help me please I need your help immediately Thanks

            Hello Friends

            1 Reply Last reply
            0
            • R Ravi Bhavnani

              No. But, I'll be more than happy to help if you have a specific question after trying to do this yourself. /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              L Offline
              L Offline
              Laji59
              wrote on last edited by
              #6

              How to use this exactly?

              Hello Friends

              R 1 Reply Last reply
              0
              • L Laji59

                How to use this exactly?

                Hello Friends

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                Iterate through the Nodes collection; check each TreeNode to see if it matches your criteria. If it does, set the control's SelectedNode property. /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                L 2 Replies Last reply
                0
                • L Laji59

                  I want to go to a specified node in TreeView. How can I do it?

                  Hello Friends

                  K Offline
                  K Offline
                  Kevin Marois
                  wrote on last edited by
                  #8

                  This example assumes that the node's Tag property contains the data (like a key value) that you're looking for:

                  public TreeNode GetTreeNode(string sNodeTag)
                  {
                  TreeNode oRetVal = null;

                  foreach (TreeNode oNode in treeView1.Nodes)
                  {
                  	if ((string)oNode.Tag == sNodeTag)
                  	{
                  		oRetVal = oNode;
                  		break;
                  	}
                  }
                  
                  return oRetVal;
                  

                  }

                  Everything makes sense in someone's mind

                  L 1 Reply Last reply
                  0
                  • K Kevin Marois

                    This example assumes that the node's Tag property contains the data (like a key value) that you're looking for:

                    public TreeNode GetTreeNode(string sNodeTag)
                    {
                    TreeNode oRetVal = null;

                    foreach (TreeNode oNode in treeView1.Nodes)
                    {
                    	if ((string)oNode.Tag == sNodeTag)
                    	{
                    		oRetVal = oNode;
                    		break;
                    	}
                    }
                    
                    return oRetVal;
                    

                    }

                    Everything makes sense in someone's mind

                    L Offline
                    L Offline
                    Laji59
                    wrote on last edited by
                    #9

                    I don`t want to get a specified node in treeview I want to set a specified node in treeview.it means I want to go to specified node in treeview How can I do it ?

                    Hello Friends

                    K 1 Reply Last reply
                    0
                    • R Ravi Bhavnani

                      Iterate through the Nodes collection; check each TreeNode to see if it matches your criteria. If it does, set the control's SelectedNode property. /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      L Offline
                      L Offline
                      Laji59
                      wrote on last edited by
                      #10

                      Thats true; but I my tree is in a larg size so I don`t want to Pass all nodes in my treeview. Now What can I do for it?

                      Hello Friends

                      1 Reply Last reply
                      0
                      • R Ravi Bhavnani

                        Iterate through the Nodes collection; check each TreeNode to see if it matches your criteria. If it does, set the control's SelectedNode property. /ravi

                        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                        L Offline
                        L Offline
                        Laji59
                        wrote on last edited by
                        #11

                        Thats true; but my tree is in a larg size so I don`t want to Pass all nodes in my treeview. Now What can I do for it?

                        Hello Friends

                        1 Reply Last reply
                        0
                        • L Laji59

                          I don`t want to get a specified node in treeview I want to set a specified node in treeview.it means I want to go to specified node in treeview How can I do it ?

                          Hello Friends

                          K Offline
                          K Offline
                          Kevin Marois
                          wrote on last edited by
                          #12

                          When you say "set a specified node in treeview", I'm guess you're talking about setting the SelectedNode. Again, this code assumes that you have stored a distinct value to each node's Tag property, and are passing that value into this method.

                          public void SetActiveNode(string sNodeTag)
                          {
                          foreach (TreeNode oNode in treeView1.Nodes)
                          {
                          if ((string)oNode.Tag == sNodeTag)
                          {
                          SelectedNode = oNode;
                          break;
                          }
                          }
                          }

                          Everything makes sense in someone's mind

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups