Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In an Explorer Prog. Treeview Like this :

First Drive:\
Folder A
SubFolder A
SubFolder B
SubFolder C

Folder B
SubFolder A1
SubFolder A2
SubFolder A3

Folder C
SubFolder AA
SubFolder BB
SubFolder CC
SubFolder DD

Folder D
SubFolder AB
SubFolder BC
SubFolder CD
SubFolder DE
SubFolder EF

NUMBER OF INDEXES:

First Drive index is (0)

Folder A index is (0)
SubFolder A1 index is (0)
SubFolder A2 index is (1)
SubFolder A3 index is (2)

Folder B index is (1)
SubFolder A1 index is (0)
SubFolder A2 index is (1)
SubFolder A3 index is (2)

Folder C index is (2)
SubFolder AA index is (0)
SubFolder BB index is (1)
SubFolder CC index is (2)
SubFolder DD index is (3)

Folder D index is (3)
SubFolder AB index is (0)
SubFolder BC index is (1)
SubFolder CD index is (2)
SubFolder DE index is (3)
SubFolder EF index is (4)


for excample

when I Select Folder C and Subfolder DD I want to get index Tree like this : (0,2,3) (Drive Node, Folder Node, SubFolder Node)
OR

when I Select Folder D and Subfolder EF I want to get index Tree like this : (0,3,4) (Drive Node, Folder Node, SubFolder Node)

How can I get this information ?

What I have tried:

VB
<pre> Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        MsgBox(TreeView1.SelectedNode.Parent.Index & "" & TreeView1.SelectedNode.NextNode.Index & "" & TreeView1.SelectedNode.NextNode.Index)

    End Sub


but not Get Drive Node and can not get the node if there are more Subfolder...
Posted
Updated 21-Mar-19 7:28am
Comments
CHill60 18-Mar-19 9:41am    
Why are you looking at the NextNode instead of the SelectedNode?

1 solution

How about:
VB.NET
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
    Dim path As New Stack(Of Integer)
    Dim node As TreeNode = TreeView1.SelectedNode
    While node IsNot Nothing
        path.Push(node.Index)
        node = node.Parent
    End While
    
    Dim nodePath As String = String.Join(",", path)
    MsgBox(nodePath)
End Sub
 
Share this answer
 
Comments
Maciej Los 21-Mar-19 15:04pm    
Looks perfect to me ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900