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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Control

Status
Not open for further replies.

ind

Programmer
Mar 9, 2000
121
US
If have created the following code the populate a treeview control:


Private Sub Form_Load()

Dim db As Database
Dim rst As Recordset
Dim rstchild As Recordset
Dim objnode As Object
Dim strKey As String
Dim strparent As String

Set db = CurrentDb
Set rst = db.OpenRecordset("tblDept")
With rst

.MoveFirst
If .RecordCount Then
Do Until .EOF
strKey = ![DeptID] & "L1"
Set objnode = trvwTest.Nodes.Add(Key:=strKey, _
Text:=![DeptID])
objnode.Sorted = True

.MoveNext
Loop
End If
.Close
End With
Set rstchild = db.OpenRecordset("tblEmployees")
With rstchild

.MoveFirst
If .RecordCount Then
Do Until .EOF
strKey = ![EmployId] & "L2"
strparent = ![DeptID] & "L1"
Set objnode = trvwTest.Nodes.Add(relative:=strparent, _
relationship:=tvwChild, Key:=strKey, _
Text:=![Name])
.MoveNext
Loop
End If
.Close
End With
db.Close
Set rstchild = Nothing
Set rst = Nothing
Set db = Nothing


End Sub

Private Sub trvwtest_NodeClick(ByVal Node As Object)

Me.Text1.Value = Node.Text
Me.Text2.Value = Need Treeview Level Number Here

End Sub

Everything works great, but I need the level number of the treeview to move to the text2 textbox.

any help is greatly appreciated....many hours spent,,,,NO LUCK!!!!!!!!!!
 
Not real sure what you mean by level number
to find where you are in a treeview you can use the following

root returns the root node in the tree
parent returns the nodes parent
child returns first child of the node
children returns the number of children the node has
firstsibling and lastsibling as well as previous and next may occassionaly come in handy
since it appears you are only building a 2 level tree you could use something like

Me.Text2.Value = iif(node.parent is nothing,"level1","level2")

or since it appears you are passing the "l1" with key just use Me.Text2.Value = right(node.key,2)

hopefully that answers your question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top