I hear ya! Others have commented on the lack of these features, too, and they are definitinely "on the radar" for the next rev of this adapter sample kit. Meanwhile, I've tried to share some of the unofficial code being considered. You might find this earlier posting interesting:
http://forums.asp.net/thread/1294834.aspx
The following enhancement to the GetNodeClass method in the TreeViewAdapter class is being considered:
private string GetNodeClass(TreeNode item)
{
string value = "AspNet-TreeView-Leaf";
if (item != null)
{
if (item.Depth == 0)
{
if (item.ChildNodes.Count > 0)
{
value = "AspNet-TreeView-Root";
}
else
{
value = "AspNet-TreeView-Root AspNet-TreeView-Leaf";
}
}
else if (item.ChildNodes.Count > 0)
{
value = "AspNet-TreeView-Parent";
}
if (item.Selected)
{
value += " AspNet-TreeView-Selected";
}
else if (IsChildNodeSelected(item))
{
value += " AspNet-TreeView-ChildSelected";
}
else if (IsParentNodeSelected(item))
{
value += " AspNet-TreeView-ParentSelected";
}
}
return value;
}
private bool IsChildNodeSelected(TreeNode item)
{
bool bRet = false;
if ((item != null) && (item.ChildNodes != null))
{
bRet = IsChildNodeSelected(item.ChildNodes);
}
return bRet;
}
private bool IsChildNodeSelected(TreeNodeCollection nodes)
{
bool bRet = false;
if (nodes != null)
{
foreach (TreeNode node in nodes)
{
if (node.Selected)
{
bRet = true;
break;
}
bRet = IsChildNodeSelected(node.ChildNodes);
}
}
return bRet;
}
private bool IsParentNodeSelected(TreeNode item)
{
bool bRet = false;
if ((item != null) && (item.Parent != null))
{
if (item.Parent.Selected)
{
bRet = true;
}
else
{
bRet = IsParentNodeSelected(item.Parent);
}
}
return bRet;
}
These enhancements follow the pattern of distinguishing the rendered markup by decorating it with additional CSS classes like AspNet-TreeView-Selected, AspNet-TreeView-ChildSelected or AspNet-TreeView-ParentSelected.
If you define these classes in your CSS files you can control the coloration, font, etc. of the selected node and parents/children above/below it on the tree.
Finally, you asked about having the tree restored to its previous state of expansion. None of the aforementioned enhancements address that... but it definitely on the radar. Your continued patience is appreciated.
Russ Helfand
Groovybits.com