• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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
0
tpiazza
Asked:
tpiazza
  • 3
  • 2
1 Solution
 
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
 
Mike TomlinsonMiddle 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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now