Windows Vista Forums

Treeview Tricky Loop
  1. #1


    Derek Hart Guest

    Treeview Tricky 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.





      My System SpecsSystem Spec

  2. #2


    Cor Ligthert[MVP] Guest

    Re: Treeview Tricky Loop

    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

    "Derek Hart" <derekmhart@newsgroup> wrote in message
    news:eNuInfo5KHA.3184@newsgroup

    > 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.
    >
    >

      My System SpecsSystem Spec

  3. #3


    Family Tree Mike Guest

    Re: Treeview Tricky Loop

    On 4/28/2010 12:04 AM, Derek Hart wrote:

    > 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.

    --
    Mike

      My System SpecsSystem Spec

  4. #4


    Jeff Johnson Guest

    Re: Treeview Tricky Loop

    "Derek Hart" <derekmhart@newsgroup> wrote in message
    news:eNuInfo5KHA.3184@newsgroup

    > 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.



      My System SpecsSystem Spec

  5. #5


    Appr3nt1c3 Guest

    Re: Treeview Tricky Loop

    On 30 Abr, 22:13, "Jeff Johnson" <i....@newsgroup> wrote:

    > "Derek Hart" <derekmh...@newsgroup> wrote in message
    >
    > news:eNuInfo5KHA.3184@newsgroup
    >

    > > 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.
    use two treeviews. clear the first one before the loop.
    then add the nodes that you dont want to delete to the new treeview

      My System SpecsSystem Spec

  6. #6


    Jeff Johnson Guest

    Re: Treeview Tricky Loop

    "Appr3nt1c3" <guerrero.rey@newsgroup> wrote in message
    news:e74ce94a-3cf3-4631-84c2-16755dc41717@newsgroup

    >> > 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.
    >
    > 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.



      My System SpecsSystem Spec

Treeview Tricky Loop problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Windows Live Mail is a tricky little fellow! N. Miller Live Mail 2 08 Jun 2009
Need to get tricky with textfiles - banging my head repeatedly joe.hurzeler PowerShell 5 12 Dec 2008
Tricky commandline parameters Ytterbium PowerShell 5 03 Jun 2008
Tricky Dual Boot Jason Vista installation & setup 7 02 Dec 2006
Drag and Drop Treeview Items between 2 Treeview ProjectGKR Avalon 3 14 Mar 2006