ASP.NET 2.0 TreeView - Programatically Selecting A TreeView Node

G

Guest

I'm building a web application that is analogous to the Windows XP file
explorer in function. The left column contains a TreeView, and the right
column a DataGrid populated by selecting TreeView nodes. The TreeView
populates dynamically as there are a significant number of nodes. The
DataGrid displays both the items and the nodes from the TreeView. Using the
explorer analogy this means the TreeView shows folders, and the DataGrid
folders and files.

The issue I have is that I would like to be able to update the TreeView to
show the selected node if the user selects the matching node from the
DataGrid. Again with the Explorer analogy, if the user selected a folder, the
folder tree would update to match the change. I'm not sure it's possible due
to the dynamic nature of the TreeView in this example as the node may not
even exist in the nodes collection (eg: The TreeView shows the root node plus
1 level but the user has drilled down 3 levels in the DataGrid from the root
node).

Any suggestions?

Kind Regards,
Tim.
 
K

Koen Hakvoort

Hello Tim,

Maybe you could try something like this
Check if a folder item is selected in a datagrid item in the
selectedindexchanged event. If so expand the folder Node in the treeview
with findnode and expand
Treeview1.FindNode("Authors\\Shakespeare").Expand(); or Select

I hope this contributes to a solution.

regards,

Koen Hakvoort
 
G

Guest

That helped. Thanks.

FYI it can be done but it gets a little ugly. Due to the dynamic nature of
the treeview you must remember to use select() and expand() when you change
nodes outside of the tree or things can get very lost. I didn't have much
luck with find node and ended up just iterating the child nodes looking for a
ValuePath match but I'll try to get FindNode working (I hate text matching -
very ugly and requires too much support code to handle unexpected input).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top