Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Events

Status
Not open for further replies.

indigoblue

Programmer
Joined
Sep 7, 2000
Messages
9
Location
GB
I have a treeview which i only want users to select the leaf nodes. The tree consists of a list of headings at the first level, with the leaves on the second level.

To automatically prevent the user selecting the nodes at the heading level, I want some code that automatically selects the first child node under the heading when the heading node is clicked. At the moment, I have the following code:

Private Sub EqualOpTree_Expand(ByVal Node As Object)

' the +/- box has been clicked...

Node.Child.Selected = True

End Sub

Private Sub EqualOpTree_NodeClick(ByVal Node As Object)

' a node has been clicked...

Dim NodeItm
NodeItm = Node.Key

' test to see if the clicked node is a heading...

Dim KeyId
KeyId = Right(NodeItm, 2)

If KeyId = "L1" Then

Node.Child.Selected = True

End If

End Sub

... the Expand event code works fine - when the +/- box is clicked, the node expands & the first child is selected. BUT the NodeClick code doesn't work: the node expands and the child node is temporarily selected, but the selection then passes back the node that was clicked. What I want to know is - why? & does anyone have a solution??

Cheers

Paul
 
Test to see which level you are by using the node properties

Firstsibling
Lastsibling
parent
root
child
children
next

I recommend

If node.children <> 0 then
treeview1.Selecteditem = node.child
 
I've got no problem with relative node properties: even if I use the code recommended, the child node gets selected and then the parent node gets reselected...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top