Treeview (Setting the selected cell in code)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use large treeviews in my application. I have trouble getting back to
where I was working when I repaint my tree. How can I in code, flag the node
I was working on before the repaint and have that node come up as being
selected after the repaint?

Thanks,
Fred Herring
 
If you are not changing the nodes in the treeview then you can store a
reference to the SelectedNode and then set that node as selected after
the repaint

TreeNode selNode = treeView.SelectedNode;
//Paint
treeView.SelectedNode = selNode

But if you are changing the nodes then you have to store some
information about the node that will help you identify the node after
creation. Maybe you can use the Tag property or the FullPath property to
identify the TreeNode after is is created again.

Let me know if you have nay doubts.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Thanks for the reply. I came to the same conclusion about saving the full
path of each node since I destroy the old tree when I repaint it. As I
repaint the new tree from the datatable containing the data, I store the full
path of each node that is created and added. Having come this far, I am now
embarassed to say, I don't know how to use the fullpath data to select a
cell. Can you show me how to select a cell programatically if you know its
full path.

Microsoft should consider giving iq tests to users before granting them msdn
subscriptions. Might screen out dumb questions like mine.

Thanks,
Fred
 
Back
Top