TreeView Help

G

Guest

I am having trouble selecting a node on a tree control. The code below is
returning me the proper index, of that I'm sure. The SelectedNode statement
returns the error Object Reference Not Set To An Object. While I'm asking, I
want to not only select the node but ensure that it is visible. In other
words, I have a tree control that displays 10 entries, but the control actual
contains thirty. Maybe the one I am trying to programmatically select can
not currently be seen without moving the scroll bar. I want it to select the
right node, and make sure that the scroll bar position has it displayed. Any
help is appreciated.

Dim sKey As String
For Each sKey In hTreeKey.Keys
Dim l As Long = CLng(hTreeKey.Item(CInt(sKey)))
If l = CLng(objPin.Name) Then
Dim t As TreeNode = treeBuiltRoutes.Nodes.Item(CInt(sKey))
treeBuiltRoutes.SelectedNode = t
Exit For
End If
Next
 
C

Cor Ligthert [MVP]

Ed,

The problem with things as treeview is that by instance a selected event is
fired, when you set that in your program. This means by instance if you do
that in your selected change event that you have quick unwanted recursion.
(Endless looping from the same event untill the stack or memory is full or
sometimes unexpected error answers).

(I have seen that you select a node in your code, however cannot see where
that is)

I hope this gives an idea.

Cor
 
G

Guest

Cor,

I don't really know what you are saying there, but here's a more
straightforward question.

The documentation says that the SelectedNode property "Gets or sets the
treenode that is currently selected in the treeview control".

The only example I can find is the "Get" portion. I can not find an example
of "set", nor can I get it to work.

Ed
 
C

Cor Ligthert [MVP]

Edb,

What I am saying with a simple pseudo code sample is

Sub DoEvent as EventChange
MyEvent += 1
End sub

This routine stops as the memory is full (or another reason) and is
something I have seen in your code.

However we don't know where you have placed that code, I must be a sub or a
function. However, what subroutine or function, do you leave as a complete
mystery for us, while that is important by setting the selected node.

I hope this helps,

Cor
 

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