Strange behaviour - arrays or treeview?

G

Guest

In hunting down a problem I created a simple form.

Public Class Form1

Private mOne As TreeNode
Private mTwo As TreeNode

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

LoadNodesA()
'LoadNodesB()

End Sub

Private Sub LoadNodesA()

mOne = TreeView1.Nodes.Add("One")
mTwo = TreeView1.Nodes.Add("Two")
TreeView1.SelectedNode = mTwo

End Sub

Private Sub LoadNodesB()

Dim nodes(1) As TreeNode
nodes(0) = New TreeNode("One")
mOne = nodes(0)
nodes(1) = New TreeNode("Two")
mTwo = nodes(1)
TreeView1.Nodes.AddRange(nodes)
TreeView1.SelectedNode = mOne

End Sub

End Class

The behaviour I wanted is given by LoadNodesA(). LoadLoadsB() gives a
different result. Can someone explain why the difference arises and why it is
meant to happen this way?

Thanks for any comments.

Hayrob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top