Hi Gary,
probably it can help you if you know the path for a certain item.
For this purpose I created 2 functions, one to get the indices and another to get the IDs from top level down to the item.
Both returning a string like this "level1;level2;..."
From this string you could e.g. also read the depth (level) of the child in the tree.
The "treeview1" is hardcoded, so if the name of your treeview is different you need to change.
If you want to modify or rename the functions, watch that both functions are recursive, so do not forget to also rename or modify the self-call.
- Code: Select all
Private function GetItemIdPath(idChild As Integer, optional BelowIdParent as integer) as string
Dim IndexChild As Integer
Dim strOut as String
Dim idP as Integer
Dim idC as integer
if isMissing(BelowIdParent) then
idP = TreeView1.InvisibleRootItem()
else
idP = BelowIdParent
endif
IndexChild = TreeView1.ChildCount(idP)
do until IndexChild <= 0
idC = TreeView1.Child(idP, IndexChild)
If TreeView1.ChildCount(idC) > 0 Then
strOut = GetItemIdPath(idChild,idC)
if strOut <> "" then
return idC & ";" &strOut
exit function
end if
end if
if idC=idChild then
strOut = idC
return strOut
exit function
end if
IndexChild = IndexChild - 1
loop
return ""
End function
Private function GetItemIndexPath(idChild As Integer, optional BelowIdParent as integer) as string
Dim IndexChild As Integer
Dim strOut as String
Dim idP as Integer
Dim idC as integer
if isMissing(BelowIdParent) then
idP = TreeView1.InvisibleRootItem()
else
idP = BelowIdParent
endif
IndexChild = TreeView1.ChildCount(idP)
do until IndexChild <= 0
idC = TreeView1.Child(idP, IndexChild)
If TreeView1.ChildCount(idC) > 0 Then
strOut = GetItemIndexPath(idChild,idC)
if strOut <> "" then
return IndexChild & ";" &strOut
exit function
end if
end if
if idC = idChild then
strOut = IndexChild
return strOut
exit function
end if
IndexChild = IndexChild - 1
loop
return ""
End function