zoukankan
html css js c++ java
TreeView状态保存
很多时候会看到,使用Treeview的时候展开这个节点,到另外一个页面的时候Treeview的状态又恢复了,下面就是解决方法咯
新建一个类
public
class
TreeViewState
...
{
public
void
SaveTreeView(TreeView treeView,
string
key)
...
{
List
<
bool
?>
list
=
new
List
<
bool
?>
();
SaveTreeViewExpandedState(treeView.Nodes, list);
HttpContext.Current.Session[key
+
treeView.ID]
=
list;
}
private
void
SaveTreeViewExpandedState(TreeNodeCollection nodes, List
<
bool
?>
list)
...
{
foreach
(TreeNode node
in
nodes)
...
{
list.Add(node.Expanded);
if
(node.ChildNodes.Count
>
0
)
...
{
SaveTreeViewExpandedState(node.ChildNodes, list);
}
}
}
private
int
RestoreTreeViewIndex;
public
void
RestoreTreeView(TreeView treeView,
string
key)
...
{
RestoreTreeViewIndex
=
0
;
RestoreTreeViewExpandedState(treeView.Nodes,
(List
<
bool
?>
)HttpContext.Current.Session[key
+
treeView.ID]
??
new
List
<
bool
?>
());
}
private
void
RestoreTreeViewExpandedState(TreeNodeCollection nodes, List
<
bool
?>
list)
...
{
foreach
(TreeNode node
in
nodes)
...
{
if
(RestoreTreeViewIndex
>=
list.Count)
return
;
node.Expanded
=
list[RestoreTreeViewIndex
++
];
if
(node.ChildNodes.Count
>
0
)
...
{
RestoreTreeViewExpandedState(node.ChildNodes, list);
}
}
}
}
在页面代码,TreeView的控件里事件里写
protected
void
TreeViewMain_Unload(
object
sender, EventArgs e)
...
{
//
save the state of all nodes.
new
TreeViewState().SaveTreeView(TreeViewMain,
this
.GetType().ToString());
}
查看全文
相关阅读:
线程池进程池
设计原则与设计模式
腾讯阿里第三方接入
计划任务
系统服务
Python Faker模块
Python openpyxl模块
Python-docx模块
进程管理
磁盘管理
原文地址:https://www.cnblogs.com/javabin/p/1583003.html
最新文章
数据清洗
计数器应用
Map Join案例
Map join
devScripts.js:5836 Warning: Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?
ant desgin pro v4 中的坑 1、后端获取的路由菜单 第一次显示 刷新浏览器后就不显示 但是数据已经请求过来 2 路由菜单正常 但浏览器 报红
浅谈静态、自适应、流式、响应式、弹性等布局的区别
怎么在html中引入vue.js文件?
react 高阶组件的使用
怎样访问 个人的博客的网站 拒绝访问情况
热门文章
【修复日常bug】解决微信小程序跳转页面全部点击事件失效!
抽奖活动插件
小程序中写动画
定位
css
前端
pymysql模块,事务
表与记录的增删改查
数据类型
mysql数据库
Copyright © 2011-2022 走看看
很多时候会看到,使用Treeview的时候展开这个节点,到另外一个页面的时候Treeview的状态又恢复了,下面就是解决方法咯
新建一个类
在页面代码,TreeView的控件里事件里写