views:

912

answers:

2

I think this is common usage in treeview, the treeview has a number of level, and I have a path say Level1 > Level2> Level3> Level4

How can I expand the treeview to Level 4 by using the path? any build in function?

Thanks.

A: 

Purely based on documentation

TreeNode mynode = treeView1.FindNode(pathToNode);
mynode.Select();
mynode.Expand();

I hope you get the starting point from here.

shahkalpesh
Care to explain when downvoting?
shahkalpesh
Does not work, will not expand child because thevchild is still hidden. Also question wants all nodes expanded.
eschneider
A: 

Dim n As System.Web.UI.WebControls.TreeNode = Me.tree.FindNode("Root/Parent 2/Child 2")

ExpandPath(n)

Private Shared Sub ExpandPath(ByVal node As System.Web.UI.WebControls.TreeNode)
    If Not node.Parent Is Nothing Then
        node.Expand()
        ExpandPath(node.Parent)
    Else
        node.Expand()
    End If
End Sub
eschneider
Getting people to go into recursion for a thing easily done with a loop will cause a lot of bad perf down the line.
ZXX
This works, why not add your own answer if you think you have a better one.
eschneider