Menu

#4 Save tree state on exit

open
nobody
None
5
2010-06-15
2010-06-15
Anonymous
No

Save tree expansion state on exit. Consider using this something based on this code?

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 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 SaveTreeViewExpandedState(TreeNodeCollection nodes, List<bool?> list)

{

foreach (TreeNode node in nodes)

{

list.Add(node.Expanded);

if (node.ChildNodes.Count > 0)

{

SaveTreeViewExpandedState(node.ChildNodes, list);

}

}

}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB