Treeview problem, cant add child nodes 
Author Message
 Treeview problem, cant add child nodes

I have the following code but the child node never shows up in the treeview.
It shows the two parent nodes but will not show any child nodes. Any ideas?
I'm using VB6 in win 2000.

thanks
Paul

Private Sub cmdView_Click()
Dim Node1, Node2, Node3, Node4 As Node

Set Node1 = tvwManufacturer.Nodes.Add
tvwManufacturer.Nodes(1).Text = "Nissan"
tvwManufacturer.Nodes(1).Key = "Nissan"

Set Node2 = tvwManufacturer.Nodes.Add("Nissan", tvwChild, "Pickups")
tvwManufacturer.Nodes(2).Text = "Pickups"
tvwManufacturer.Nodes(2).Key = "Pickups"

Set Node3 = tvwManufacturer.Nodes.Add("Nissan", tvwNext, "Sedans")
tvwManufacturer.Nodes(3).Text = "Sedans"
tvwManufacturer.Nodes(3).Key = "Sedans"

Set Node4 = tvwManufacturer.Nodes.Add("Nissan", tvwChild, "Extended Cab")
tvwManufacturer.Nodes(4).Text = "Extended Cab"
tvwManufacturer.Nodes(4).Text = "Extended Cab"

End Sub



Fri, 26 Nov 2004 05:51:40 GMT  
 Treeview problem, cant add child nodes
Paul,

The TreeView is probably one of the most misunderstood and scary
controls to work with. But once learnt, is a very useful control to
have in your kit.

Have you tried double-clicking on "Nissan" node? It does expand to
reveal "Pickups" and "Extended Cab". The reason why you can see the
expand/collapse (Plus/Minus) image is due to the TreeView's default
settings: LineStyle = '0 - tvwTreeViewLines'. This is used if you have
one or more root nodes expanded when created:-

  Set Node1 = tvwManufacturer.Nodes.Add("Nissan", , "Nissan")
  Node1.Expanded = True

If this was not the desired effect, then I'd suggest changing the
LineStyle to '1 - tvwRootLines'.

I've also noticed that you're doubling up on setting node properties:-

  Set Node2 = tvwManufacturer.Nodes.Add("Nissan", tvwChild, "Pickups")
  tvwManufacturer.Nodes(2).Text = "Pickups"
  tvwManufacturer.Nodes(2).Key = "Pickups"

Should just be:-

  Set Node2 = tvwManufacturer.Nodes.Add("Nissan", tvwChild, "Pickups")

Or if the node is just a child node:-

  tvwManufacturer.Nodes.Add "Nissan", tvwChild, "Pickups"

Then, to reference the node:-

  Dim oNode as MSComctlLib.Node
  set oNode = tvwManufacturer.Nodes("Pickups")
  With oNode
    Debug.Print "Node Caption = " + oNode.Text
  end with

or

 Debug.Print "Node Caption = " + tvwManufacturer.Nodes("Pickups").Text

Hope this helps!

Graeme.

Quote:

>I have the following code but the child node never shows up in the treeview.
>It shows the two parent nodes but will not show any child nodes. Any ideas?
>I'm using VB6 in win 2000.

>thanks
>Paul

[...Trimmed...]


Fri, 26 Nov 2004 08:46:34 GMT  
 Treeview problem, cant add child nodes
Thanks very much, the expanded property did the trick!

Thanks again
Paul

Quote:

> Paul,

> The TreeView is probably one of the most misunderstood and scary
> controls to work with. But once learnt, is a very useful control to
> have in your kit.

> Have you tried double-clicking on "Nissan" node? It does expand to
> reveal "Pickups" and "Extended Cab". The reason why you can see the
> expand/collapse (Plus/Minus) image is due to the TreeView's default
> settings: LineStyle = '0 - tvwTreeViewLines'. This is used if you have
> one or more root nodes expanded when created:-

>   Set Node1 = tvwManufacturer.Nodes.Add("Nissan", , "Nissan")
>   Node1.Expanded = True

> If this was not the desired effect, then I'd suggest changing the
> LineStyle to '1 - tvwRootLines'.

> I've also noticed that you're doubling up on setting node properties:-

>   Set Node2 = tvwManufacturer.Nodes.Add("Nissan", tvwChild, "Pickups")
>   tvwManufacturer.Nodes(2).Text = "Pickups"
>   tvwManufacturer.Nodes(2).Key = "Pickups"

> Should just be:-

>   Set Node2 = tvwManufacturer.Nodes.Add("Nissan", tvwChild, "Pickups")

> Or if the node is just a child node:-

>   tvwManufacturer.Nodes.Add "Nissan", tvwChild, "Pickups"

> Then, to reference the node:-

>   Dim oNode as MSComctlLib.Node
>   set oNode = tvwManufacturer.Nodes("Pickups")
>   With oNode
>     Debug.Print "Node Caption = " + oNode.Text
>   end with

> or

>  Debug.Print "Node Caption = " + tvwManufacturer.Nodes("Pickups").Text

> Hope this helps!

> Graeme.


> >I have the following code but the child node never shows up in the
treeview.
> >It shows the two parent nodes but will not show any child nodes. Any
ideas?
> >I'm using VB6 in win 2000.

> >thanks
> >Paul

> [...Trimmed...]



Fri, 26 Nov 2004 10:42:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. treeview node count not incrementing when adding new nodes

2. Treeview is the node a child

3. TreeView child nodes

4. Enumerate Treeview child nodes

5. TreeView- Accessing children under node

6. Sheridan TreeView - Ordering Child Nodes

7. Moving nodes in Treeview with children

8. Moving nodes in Treeview with children

9. Sorting Child Nodes in a Treeview

10. Move Treeview Child Node To Different Parent

11. Opening a Treeview to a child node

12. Count of Children under a TreeView Node

 

 
Powered by phpBB® Forum Software