Quick treeview question

K

Kay

Hi all,

I have a treeview, each node's tag has a value. What I'm trying to do is
when a user click on a child node, I want to get the parent's tag value.
The problem i'm having is I don't know whether the selected node has a
parent or not... could u help?

Thanks~

Kay
 
S

Scott M

You could store a reference to the parent in the tag value. That would mean
you'd have to create a custom class to hold the information that you need
AND the parent.
 
C

Cor Ligthert [MVP]

P

Phill. W

The problem i'm having is I don't know whether the selected node
has a parent or not...

Every Node has a Parent property that holds a reference to
its immediate Parent Node, or nothing if it's at the root level,
as in :

If Not( tv.SelectedNode.Parent is Nothing ) then
Zap( tv.SelectedNode.Parent.Tag )
End If

(I /think/ it's SelectedNode - might be SelectedItem; haven't got
'Studio to hand at the moment).

HTH,
Phill W.
 
H

Herfried K. Wagner [MVP]

Phill. W said:
If Not( tv.SelectedNode.Parent is Nothing ) then
Zap( tv.SelectedNode.Parent.Tag )
End If

(I /think/ it's SelectedNode - might be SelectedItem; haven't got
'Studio to hand at the moment).

It's actually 'SelectedNode' :).
 
K

Kay

Thanks a lot guys!

Cor thanks for remind me that, I tried the VS help (looked into the parent
property) but I didn't get what I need, now I know the online version is
different from the VS help!
 

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