本文介绍了展开和折叠树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用treeview
,在其中我只想扩展选中的node
,而其他的则是折叠.我使用了代码来执行此操作,但是我想知道如何在pageload
运行代码的地方.
我的代码如下:
I am using a treeview
,in which i want to expand that node
only which is selected,and others are collapse.I have used a code for doing this,but i want to know that how to bind the tree on pageload
by which the code is run.
my code is given below:
protected void Tree_SelectNodeChange(object sender, EventArgs e)
{
var tree = (TreeView)sender;
foreach (TreeNode node in tree.Nodes)
{
node.CollapseAll();
}
ExpandToRoot(tree.SelectedNode);
}
private void ExpandToRoot(TreeNode node)
{
node.Expand();
if (node.Parent != null)
{
ExpandToRoot(node.Parent);
}
}
感谢
thanks
推荐答案
这篇关于展开和折叠树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!