KAL
KAL

Reputation: 79

How to expand a selected treeview node

I just coded as below to expand a selected node after a postback. But it is not working. What am I missing?

trvMenu.CollapseAll();
//TreeNode searchNode = trvMenu.FindNode(selectedNode.Text); // Updated
//TreeNode searchNode = trvMenu.FindNode(selectedNode.Value);
TreeNode searchNode = trvMenu.FindNode(selectedNode.ValuePath);
if (searchNode != null)
  searchNode.ExpandAll();

selectedNode.Selected = true;

//selectedNode.Selected = true;
//selectedNode.ExpandAll();

Image: (Updated)
enter image description here

Upvotes: 1

Views: 1306

Answers (1)

Jaroslav Kubacek
Jaroslav Kubacek

Reputation: 1447

If I'm correct method FindNode definition is:

public TreeNode FindNode(
string valuePath)

but in your example is trvMenu.FindNode(selectedNode.Text); Just try to put trvMenu.FindNode(selectedNode.ValuePath);

Upvotes: 1

Related Questions