I have an ASP.net TreeView control which displays a hierarchical folder structure. Each node in the TreeView has a Long value property corresponding to a FolderId; the Text property is the Folder Name, like so:
TreeNode node = new TreeNode();
node.Text = "folder name";
node.Value = 12345;
nodes.Add(node);
I need to auto expand the TreeView to a specific node by passing in the FolderId.
The TreeView has a FindNode() method which seems to take a “value path” (string) property. This is as far as I can get:
string folderIdPath = "72|73|77";
TreeView1.PathSeparator = '|';
TreeView1.FindNode(folderIdPath).Expand();
However, this throws an “Object reference not set to an instance of an object” error.
So it turns out that you can’t actually expand a TreeView all in one go. You have to do it one node at a time, see here : http://forums.asp.net/t/1099367.aspx/1
So now I loop through all the FolderIds and open them one at a time. The important thing to remember is that although you open them one at a time, you still need to use the full valuepath.
See the link above for more info.