By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 1,966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Recreate a >>C# WinForms<< TreeView "state" -after- treeview rebuild ?? Any TreeView GODS out there ??

P: n/a
I have a C# WinForms treeview with 20 or so 'level 0' nodes.

My users will normally have 2 of the 'level 0' branches open down to a '5th
level' selected node.

The users will make updates to the 2 selected nodes that will alter the node
name.

I think I need to rebuild the TreeView to get everything synchronized after
they click an update button.

Is there an example somewhere that shows how to recreate and re-expand level
0 branches of the TreeView state after the Tree has been rebuilt?

Put another way ... At the time the user commits an update the Level 0 nodes
5 and 18 are open 'down' to a pair of selected 5th level nodes. One node per
branch. All the other level 0 nodes are collapsed.

How do I rebuild the treeview and open the 5 and 18 level 0 nodes down to
the 5th level and reselect the 5th level nodes that the users had
previously selected and updated ?? I can save the names of the previously
selected and updated nodes. I'm just unsure of how to selectively expand
the 5 and 18 level 0 branches down to the 5th level and reselect the target
nodes.

Any help would be GREATLY appreciated.

Thanks in advance.

Barry in Oregon

Aug 15 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
frostbb wrote:
How do I rebuild the treeview and open the 5 and 18 level 0 nodes down to
the 5th level and reselect the 5th level nodes that the users had
previously selected and updated ?? I can save the names of the previously
selected and updated nodes. I'm just unsure of how to selectively expand
the 5 and 18 level 0 branches down to the 5th level and reselect the target
nodes.
Save the state of ANY node that is expanded. When rebuilding the tree,
after inserting a node and inserting its children, check to see if its
one of your saved expanded nodes, and expand it.
For storing which items are expanded, I'd store the full path to the
node from the root.

--
Joel Lucsy
"The dinosaurs became extinct because they didn't have a space program."
-- Larry Niven
Aug 15 '08 #2

P: n/a

frostbb wrote:
I have a C# WinForms treeview with 20 or so 'level 0' nodes.

My users will normally have 2 of the 'level 0' branches open down to a '5th
level' selected node.

The users will make updates to the 2 selected nodes that will alter the node
name.

I think I need to rebuild the TreeView to get everything synchronized after
they click an update button.
Not necessarily. If you can track the specific changes that are
happening to the data source from which the tree is loaded, you can
avoid the full rebuild, instead just inserting, removing or moving the
nodes that were changed. And that will preserve the collapsed/expanded
state of all nodes.
Aug 15 '08 #3

P: n/a
Thanks for the reply. Hadn't considered simply dropping and recreating the
existing nodes. In this case I may actully be able to get away with that!
I'm pretty sure I can get this thing to work using your and the other
replies to my question.

Best wishes. Happy computing and THANKS!

Barry in Oregon

"Pavel Minaev" <in****@gmail.comwrote in message
news:9c**********************************@f36g2000 hsa.googlegroups.com...
>
frostbb wrote:
>I have a C# WinForms treeview with 20 or so 'level 0' nodes.

My users will normally have 2 of the 'level 0' branches open down to a
'5th
level' selected node.

The users will make updates to the 2 selected nodes that will alter the
node
name.

I think I need to rebuild the TreeView to get everything synchronized
after
they click an update button.

Not necessarily. If you can track the specific changes that are
happening to the data source from which the tree is loaded, you can
avoid the full rebuild, instead just inserting, removing or moving the
nodes that were changed. And that will preserve the collapsed/expanded
state of all nodes.

Aug 18 '08 #4

P: n/a
Joel,

Thanks for the reply. Really appreciate your time and knowledge. I'm pretty
sure I can get this to work using your
and the other replies to my question.

Best wishes. Happy computing and THANKS!

Barry in Oregon
"Joel Lucsy" <jj*****@gmail.comwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
frostbb wrote:
>How do I rebuild the treeview and open the 5 and 18 level 0 nodes down to
the 5th level and reselect the 5th level nodes that the users had
previously selected and updated ?? I can save the names of the
previously selected and updated nodes. I'm just unsure of how to
selectively expand the 5 and 18 level 0 branches down to the 5th level
and reselect the target nodes.

Save the state of ANY node that is expanded. When rebuilding the tree,
after inserting a node and inserting its children, check to see if its one
of your saved expanded nodes, and expand it.
For storing which items are expanded, I'd store the full path to the node
from the root.

--
Joel Lucsy
"The dinosaurs became extinct because they didn't have a space
program." -- Larry Niven

Aug 18 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.