Click here to Skip to main content
14,031,046 members
Rate this:
 
Please Sign up or sign in to vote.
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:

<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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

How about:
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
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190419.4 | Last Updated 21 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100