WebTreeView中,如何在新增了一個子節點後,將該節點設定為選中狀態?
需寫一個遞迴程式:
public TreeNode Find(TreeNode node)
{
if(node.Text == "YourText") return node;
for (int i = 0; i < node.ChildNodes.Count; i++)
{
TreeNode nd = Find(node.ChildNodes[i]);
if (nd != null)
return nd;
}
return null;
}
再寫一個查找,比如放在ButtonClick:
TreeNode node = null;
for (int i = 0; i < WebTreeView1.Nodes.Count; i++)
{
node = Find(WebTreeView1.Nodes[i]);
if (node != null) break;
}
node.Select();