Treeview nade access problem

J

James Hahn

I am using the text in a treeview to access some internal data that is
contained in the first child of a parent. It is accessed in the AfterSelect
event using ByVal e As System.Windows.Forms.TreeViewEventArgs. The node
contains valid data, as indicated by the text displayed in the control, and
the fact that when I select the relevant (child) node the following code
works and I can also see a correct value in the debugger if I pause at this
line:

Nodelist.Add(fht(Mid(e.Node.Text, 5)))

But I cannot access the same node if I click on the parent and attempt to
access the first child node:

Nodelist.Add(fht(Mid(e.Node.Nodes(0).Text, 5)))

The above line returns a meaningless value. I can't look at the text for the
node in the debugger because it shows:
e.node.nodes
Count: 11
IsReadOnly: No
Item: In order to evaluate an indexed property the property must be
qualified and the arguments must be explicitly supplied by the user.

Why is it referring to item and not text, and why is it telling me I have
not qualified the property properly? It's as if an element of the nodes
collection cannot have a text property. Is this some result of accessing the
control through the TreeViewEventArg?
 
J

James Hahn

I've solved it.

Replacing
Nodelist.Add(fht(Mid(e.Node.Nodes(0).Text, 5)))

with
Dim tn As TreeNode = e.Node.Nodes(0)
Nodelist.Add(fht(Mid(tn.Text, 5)))

works but I have no idea why I should need to make that change.
 

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