Trouble with Treeview vb.net 2005 express

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JRSofty
    New Member
    • Aug 2007
    • 2

    Trouble with Treeview vb.net 2005 express

    Hi everyone,

    I've gotten myself is bit of a mess where I'm loading a treeview. Basically I initialize the treeview control with a single root node we'll call it root. I do this by using the following syntax:
    Code:
    Dim tNode as TreeNode = New TreeNode("root")
    tNode.name = "root"
    TreeView1.Nodes.Add(tNode)
    Now that I've gotten my root node set, I proceed to pass this node to another sub where some children are loaded to the node. The node is passed ByRef (as I think it should be since I'm changing the node a bit by adding children). I then call up the information for the children and proceed to add them to the root node that has been passed using much the same type of syntax as above. This is fine and this works.

    The problem is that when the form is finally displayed I'm getting the root node added twice in the treeview control. Both have the children loaded. However, if I do a TreeView.Nodes. Count check it says there is only one node and not two.
    It kind of looks like this:
    Code:
    root
       |
       |-Child 1
       |-Child 2
       |-Child 3
    root
       |
       |-Child 1
       |-Child 2
       |-Child 3
    Is this a bug in the TreeView control? I've double checked my code and I'm sure I'm only adding the root node once. Why is it being displayed twice with the exact same information?
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by JRSofty
    Hi everyone,

    I've gotten myself is bit of a mess where .............
    this by using the following syntax:
    [CODE=vb]Dim tNode as TreeNode = New TreeNode("root" )
    tNode.name = "root"
    TreeView1.Nodes .Add(tNode)[/CODE]

    The node is passed ByRef (as I think it should be since I'm changing the node a bit by adding children).
    I think you are adding root node two times 1 out side the method (As you mentioned above) and also inside the method. Just check once.

    Comment

    Working...