Retrieve Treenode from treeview

0
0

Hi,

I filled a hiearchical treeview using unique key for each node.

When i try to retrieve node using key , result is always nothing.

I tested with a short proc. The name of clicked node  is correctly displayed, but newnode is nothing.

Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
Dim newnode As TreeNode
MsgBox(e.Node.Name)

                             ‘                     Trying to get node using key(name)
newnode = TreeView1.Nodes(e.Node.Name)
MsgBox(newnode.Name)

End Sub

What is wrong ?

I am using last Wisej version (2.2.9)

Thks

Nello Pernice

  • You must to post comments
0
0

Thank you,

waiting your answer, i discovered the problem. so i have changed my procedure to find specific node navigating through the nodes, and it works correctly.

When treeview  contains a lot of nodes, this approach  is more efficient than use TreeView1.Nodes.Find(key, searchChildren).

Bye

 

 

  • You must to post comments
0
0

The Nodes collection indexer searches only the immediate children. TreeView1.Nodes(name) will find the node in TreeView1.Nodes only. To search deep use TreeView1.Nodes.Find(key, searchChildren). It returns an array of found nodes with the key is pass true for searchChildren.

  • You must to post comments
0
0

Yes,  i assigned name property using two different methods:

1)Assigning Key in ADD operation

r2 = r1.Nodes.Add(i0 & “_” & i1, “1 naming”)

2)Assigning direclty property:

r2.Name = i0 & “_” & i1

When i click on the node, the value of the property “name” is correctly retrieved :

Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
MsgBox(e.Node.Name)

But when i try to retrieve node using the same property value , result is always “Nothing”

Dim newnode As TreeNode
newnode = TreeView1.Nodes(e.Node.Name)
MsgBox(newnode.Name)

See Attached file with  my code

 

 

 

Attachment
  • You must to post comments
0
0

Did you assign the Name property? The Name is “” by default and is different from the Text.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.