471,330 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

TreeView - Reloading the treeView and expanding the last selected

Hi,

I have a treeview that has to be refreshed due to data changes. Is it
possible to select the last node that they were viewing when the tree view
was been populated once again?

I have tried getting the selected node and then expanding it in the
refreshed tree view using expand() but it does not do it.

Thanks for any help.
Dec 5 '05 #1
1 9368
Are you clearing out the tree when you fresh it, or just updating the
existing nodes without removing them?

If you clear the nodes from the tree, then the selected node no longer
exists and therefore you cannot expand it. In this case you will need a path
to follow up the tree to the root, then once the tree is refreshed, you will
need to follow this path back down from the root to find the node that should
be selected and then select and expand it. Determining how you will find a
path to follow is dependent on the data stored in the tree and how it is
stored.

If you are just refreshing the existing nodes, create a TreeNode reference
and set it equal to the TreeView.SelectedNode before refreshing, then once
refreshed use the TreeNode.Expand() method from the reference you made.

private void BeginRefreshTreeView()
{
TreeNode selected = TreeView.SelectedNode();
this.RefreshTreeView();
selected.Expand();
}

private void RefreshTreeView()
{
//Do your refresh (make sure not to remove the nodes though)
}

If this doesn't help, please post an example of what is stored in the tree
and how you are refreshing it.

Chris

"James L" wrote:
Hi,

I have a treeview that has to be refreshed due to data changes. Is it
possible to select the last node that they were viewing when the tree view
was been populated once again?

I have tried getting the selected node and then expanding it in the
refreshed tree view using expand() but it does not do it.

Thanks for any help.

Dec 5 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by clsmith66 | last post: by
4 posts views Thread by Karim El Jed | last post: by
7 posts views Thread by vsiat | last post: by
2 posts views Thread by Claus | last post: by
1 post views Thread by doemon | last post: by
1 post views Thread by Rick | last post: by
26 posts views Thread by JJ | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.