View Full Version : [CLOSED] Expanding tree programmatically

Apr 12, 2015, 5:13 PM

Is it possible to expand a treepanel to a node from the code behind?

I have an application that stores the last node selection that a user has made in a database and I want to make the website in such a way that next time it opens with the last selected node.

The treepanel contains a treestore with the method 'OnReadData' to fill the tree when nodes are selected.

Any idea how to approach this? In VB/C# or in the javascript part of ext.net?
Is it possible when not all data is loaded?

Hans Wapenaar

Apr 12, 2015, 9:42 PM
In OnReadData set the node's Expanded property accordingly.

Apr 13, 2015, 7:52 AM
Ok, but I thought that OnReadData works when the user clicks on a node in the treepanel. After the user clicks on a node the contents of the ChildNodes is filled and the node is expanded.
What I'm searching for is a method to expand a node programatically and not through the user interface.

Apr 13, 2015, 8:51 AM
In OnReadData you add the child nodes programmatically, don't you?

If so, you can also set which child node is expanded. The following example adds five new child nodes and programmatically expands the 4th one. You can modify the logical expression to check against the value stored in your database.

protected void OnReadData(object sender, NodeLoadEventArgs e)
for (int i = 1; i < 6; i++)
Node treeNode = new Node();
treeNode.Text = i.ToString();
treeNode.NodeID = i.ToString();
treeNode.Expanded = (i == 4);