简体   繁体   中英

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)
在此处输入图片说明

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 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM