winform如何保持TreeView节点展开和折叠的状态
跟着阿笨一起玩NET
发布
于
2018-09-19 16:57:37
发布
于
2018-09-19 16:57:37
转载: http://blog.sina.com.cn/s/blog_6abcacf5010138q5.html
private Hashtable NodesStatus = new Hashtable();
private string SelectNodeFullPath = string.Empty;
/// <summary>
/// </summary>
/// <param name="nodes"></param>
private void GetTreeNodesStatus(TreeNodeCollection nodes)
foreach (TreeNode node in nodes)
if (node.IsExpanded)
NodesStatus[node.FullPath] = true;
NodesStatus.Remove(node.FullPath);
if (node.IsSelected)
SelectNodeFullPath = node.FullPath;
GetTreeNodesStatus(node.Nodes);
/// <summary>
/// </summary>
/// <param name="nodes"></param>
private void SetTreeNodesStatus(TreeNodeCollection nodes)
foreach (TreeNode node in nodes)
if (NodesStatus[node.FullPath] != null)
node.Expand();
if (node.FullPath == SelectNodeFullPath)
this.tvAuthFuction.SelectedNode = node;