find which treeview node is clicked

i have a trreview that i am trying to find the selected node and sometime the one above it

works fin wit hte following

TextBox1.Text = trvReaders.SelectedNode.Text & "  " & trvReaders.SelectedNode.Parent.Text

problem is when i click on the top node it locks up becuase there isnt a parent node


how do i get around this it 3 nodes deep
tpiazzaAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You have to set OwnerDraw to True and then render each individual row yourself via code.

This isn't trivial:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.ownerdraw.aspx

It would probably be easier to implement an OwnerDraw ListBox with alternating colors.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Test for the existence of a Parent...

If Not IsNothing(trvReaders.SelectedNode.Parent) Then
    TextBox1.Text = trvReaders.SelectedNode.Text & "  " & trvReaders.SelectedNode.Parent.Text
Else
    TextBox1.Text = trvReaders.SelectedNode.Text
End If
0
 
tpiazzaAuthor Commented:
thanks -- do you know how to make the rows in listview alternate color?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's a completely different question...  =)

You can reduce this one to 20 points if you want.  Then ask another about the ListView.
0
 
tpiazzaAuthor Commented:
raised it 20 -- do you know how to do it?  the entire listview goes one color or the other
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.