Treeview Tricky Loop

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

No idea how to do this. Have a treeview with lots of nodes. Need to loop
through the nodes, and remove ones (that have a specific tag). That is easy.
But I don't want to remove the nodes under the ones removed. I want them to
"move up" a notch, and only get deleted if they have a specific tag. Help!
So each node is looked at, but no child nodes are remove until it is their
turn to be analyzed.
 
Derek,

Nice puzzle (but that are all Treeviews) seems to me a real challenge for
you.

Be aware that for all deleting in collections doing it bottom up makes
things much easier like I once learned from Armin.

For i = Count-1 (lenght-1) to 0 step -1

Success

Cor
 
No idea how to do this. Have a treeview with lots of nodes. Need to loop
through the nodes, and remove ones (that have a specific tag). That is easy.
But I don't want to remove the nodes under the ones removed. I want them to
"move up" a notch, and only get deleted if they have a specific tag. Help!
So each node is looked at, but no child nodes are remove until it is their
turn to be analyzed.

Think about using a while loop rather than going once through in a
foreach loop. While you can find a node who's tag is desired, then you
want to do your edits. This avoids the problems with deleting items in
a foreach loop.
 
No idea how to do this. Have a treeview with lots of nodes. Need to loop
through the nodes, and remove ones (that have a specific tag). That is
easy. But I don't want to remove the nodes under the ones removed. I want
them to "move up" a notch, and only get deleted if they have a specific
tag. Help! So each node is looked at, but no child nodes are remove until
it is their turn to be analyzed.

Three loops.

First, create a List(Of TreeNode). Then loop the entire tree. When you find
nodes that you want to delete, add them to the list.

Next, iterate the list. The first thing you'll need to do is iterate the
children of the active item (third loop) and set their Parent to the Parent
of the active item. This moves them "up a notch." Once that's done, delete
the node.
 
Three loops.

First, create a List(Of TreeNode). Then loop the entire tree. When you find
nodes that you want to delete, add them to the list.

Next, iterate the list. The first thing you'll need to do is iterate the
children of the active item (third loop) and set their Parent to the Parent
of the active item. This moves them "up a notch." Once that's done, delete
the node.

use two treeviews. clear the first one before the loop.
then add the nodes that you dont want to delete to the new treeview
 
use two treeviews. clear the first one before the loop.
then add the nodes that you dont want to delete to the new treeview

If you clear the first tree view, where are the nodes supposed to come from
to fill the second?

Regardless, this really sounds like overkill to me.
 
Back
Top