TreeNode.FullPath
-
Hello, If I have a full path to the selected node, is there a way to expand the treeview after I refresh it, to that particular node using the path? Thank you!
string nodeToFind = "node11"; // node's you want to show name TreeNode[] nodes = treeView1.Nodes.Find(nodeToFind, true); if(nodes != null && nodes.Length > 0){ TreeNode node = nodes[0]; while(node != treeView1.TopNode){ node.Parent.Expand(); node = node.Parent; } }
life is study!!!
-
string nodeToFind = "node11"; // node's you want to show name TreeNode[] nodes = treeView1.Nodes.Find(nodeToFind, true); if(nodes != null && nodes.Length > 0){ TreeNode node = nodes[0]; while(node != treeView1.TopNode){ node.Parent.Expand(); node = node.Parent; } }
life is study!!!
-
Hello, If I have a full path to the selected node, is there a way to expand the treeview after I refresh it, to that particular node using the path? Thank you!
Whenever you add a node, get its full path and store it into node's name.
TreeNode tn = this.treeView1.Nodes.Add("AAA"); tn.Name = tn.FullPath;
When you want to expand the node having, let's say,"The_wanted_path"
you use this:TreeNode [] tn = this.treeView1.Nodes.Find("The_wanted_path", true);
if ( tn[0] != null )
{
TreeNode Parent = tn[0].Parent;
TreeNode FirstParent = Parent;
while (Parent != null)
{
Parent = Parent.Parent;
if (Parent != null) FirstParent = Parent;
}
tn[0].Expand();
if (FirstParent != null) FirstParent.Expand();
}SkyWalker