展开和折叠树视图 [英] Expand and collapse tree view

查看:83
本文介绍了展开和折叠树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用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

推荐答案

我假设这是WinForm. WinForm上的所有内容都是手动的,这意味着您必须折叠每个节点.我建议您保留一个指向最近扩展的节点的指针,并在选定的节点事件上保留指向该节点的指针,并折叠该节点及其父节点.
I am assuming that this is WinForm. Everything on WinForm is manual, which means that you will have to collapse every node. I would recommend that you keep a pointer to the most recently expanded node, and on the node selected event, to to that node and collapse the node and its parents.


这篇关于展开和折叠树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆