Results 1 to 4 of 4

Thread: [2005] TreeNode For Each

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    [2005] TreeNode For Each

    I'm having issues with iteriating treenodes.

    I've got a database table with the following columns:
    CategoryID
    CategoryName
    ParentID

    I set the Node name to CategoryID and the .Tag property to the ParentID.

    Items with ParentID = 0, Tag is Nothing.

    Now, I iteriate through nodes and start moving them around:
    Code:
            For Each mNode As TreeNode In control.Nodes
                If Not IsNothing(mNode.Tag) Then
                    mNode.Remove()
                    'control.Nodes(mNode.Tag.ToString).Nodes.Add(mNode)
                    MsgBox(mNode.Tag)
                    control.Nodes(control.Nodes.IndexOfKey(mNode.Tag)).Nodes.Add(mNode)
                End If
            Next

    The issue is that for some reason, it won't add more than 2 child nodes to a parent. Even though the data is right.

    Heres what the result looks like:
    + Windows
    -Security
    -Productivity
    + Ubuntu
    -Design
    +Tools

    Heres what is should be:
    + Windows
    -Security
    -Productivity
    -Tools
    +Ubuntu
    -Design

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2005] TreeNode For Each

    What happens when you code encounters the Tools node? What is the Tools node's tag property set to?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] TreeNode For Each

    2, which is what Windows is set to.

    I cleared out the rows and now I'm finding more issues.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] TreeNode For Each

    Well, I kinda of figured it out, I just looped through the For Each like 10 times, which is not the best way, but it works for now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width