-1

i was breaking my head with this, i will explain i have a treeview and i need to find a node, i have the node's id, but i want to save the trace of the node in a list

e.g. if i want to find node 1.2.1.1

 node1
    node1.1
      node 1.1.1
      node 1.1.2
      node 1.1.3
    node 1.2
      node 1.2.1
        node 1.2.1.1
    node 1.3 

my list should have {node1,node1.2,node1.2.1,node 1.2.1.1}

i made some code but it is not working please help! i will be very thankful

this is my code

        foreach (SFFolder item in folderBrowserTreeView.Items)
            {

                JumpToNode(item, recoveryFolderID);
            }


void JumpToNode(SFFolder tvi, string folderID)
   {
       if (tvi.Id == folderID)
       {
           folderBrowserTreeView.Focus();
           tvi.IsExpanded = true;
           tvi.IsSelected = true;
           return;
       }
       else
           tvi.IsExpanded = true;

       if (tvi.HasChildren)
       {
           tvi.Childrens = _apiShareMethods.GetChildrens(_token, tvi.Id);//this add new                children from the rest api
           foreach (var item in tvi.Childrens)
           {
               SFFolder temp = item as SFFolder;
               JumpToNode(temp, folderID, localPath);
           }
       }

this code expand all the nodes before found the node that i am trying to found, and what i want is just expand the path of the wanted node

user2984254
  • 109
  • 1
  • 7
  • 1
    Let's have a look at the code - you never know, you may only be a small change away from getting it... – dyson Jul 17 '14 at 22:16
  • 1
    You can use the FullPath property of the node. Use the TreeView's PathSeparator property to split the text back into a string of array items. – LarsTech Jul 17 '14 at 22:27

1 Answers1

0

I think this will help you if you declare all your intentions right in the question:

var node = treeView1.Nodes.Find("Node1.2.1.1", true).First();
string[] path = node.FullPath.Split(new string[] { "\\" },StringSplitOptions.RemoveEmptyEntries);
var nodes = from s in path
            let n = treeView1.Nodes.Find(s, true).First()
            select n

;

terrybozzio
  • 4,424
  • 1
  • 19
  • 25