Hi guys
I'm needing to create a fairly complex TreeView, but am faltering on a very
basic step (as you will gather, I'm new-ish to .net).
Simplified, I can't get the creation of two nodes (with children) to work.
I've got a TreeView called tvwSword and have put the following code into the
Form1_Load:
Dim nodeParent As TreeNode
Dim nodeChild As TreeNode
nodeParent = New TreeNode("2001")
tvwSword.Nodes.Add(nodeParent) ' adds parent of 2001
nodeParent.Nodes.Add("2001/1") ' adds child of 2001/1 to parent of 2001
nodeParent = New TreeNode("2002")
tvwSword.Nodes.Add(nodeParent) ' adds parent of 2002
nodeParent.Nodes.Add("2002/1") ' adds child of 2002/1 to parent of 2002
' the above lines work fine
nodeParent = New TreeNode("2001")
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Insert(1, nodeChild) ' adds child of 2001/2 to parent of
2001
' these 3 lines do nothing ?????
tvwSword.Show()
Now, I would have expected this to read:
2001
--- 2001/1
--- 2001/2
2002
--- 2002/1
but it doesn't insert the second child (2001/2).
If I change it to
nodeParent = New TreeNode("2001")
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Add(nodeChild)
I get the same effect.
Under VB6.0 I would have used keys and the problem of children is resolved,
but I can't see how to do it in VB.Net. I think it may be something to do
with SelectedNode, but I can't see what.
What am I missing????
TIA
Rabbit