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());
}
查看全文
相关阅读:
URL编码和Bsae64编码
在控制台保存下载数据文件方法
前端下载文件的几种方式
npm i error:0909006C:PEM routines:get_name:no start line 遇到问题解决
MapTalks.js 使用小结(三): 各类地图加载
在线瓦片地图服务资源 总结
npm webpack 遇到的问题解决方案总结
MapTalks.js 使用小结(二)
可拖动的进度条 in vue
滚动条vue-seamless-scroll的使用
原文地址:https://www.cnblogs.com/javabin/p/1583003.html
最新文章
常用命令
常用正则表达式收集
Gitlab搭建以及CI/CD
扩展ubuntu /home磁盘空间
c++ boost Json 生成与解析
git submodule 与cmake(以Gflags glog为例)
gcc 内建函数
c++11 std::forward使用场景以及作用
c++11 std::move移动构造引用相关释义
c++11 中的函数回调方式
热门文章
答应我,别在go项目中用init()了
精度损失而引发的 bug
为代码编写稳定的单元测试 [Go]
利用 uber-go/dig 库管理依赖
goland live template 牛刀小试
[翻译] Kubernetes 101: Pods, Nodes, Containers, and Clusters
Go 的 类型定义 和 类型别名 (Type Alias Declarations)
macOS 真香与一个创建日记的脚本
类型的本质:对变量、类型、指针的理解
go 技巧: 实现一个无限 buffer 的 channel
Copyright © 2011-2022 走看看
很多时候会看到,使用Treeview的时候展开这个节点,到另外一个页面的时候Treeview的状态又恢复了,下面就是解决方法咯
新建一个类
在页面代码,TreeView的控件里事件里写