How do I make a directory Treeview populate the sub-folder and files?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
smjadtnf707
Posts: 32
Joined: Sun May 19, 2019 7:26 pm

How do I make a directory Treeview populate the sub-folder and files?

Post by smjadtnf707 » Sat Jun 08, 2019 9:14 am

Hello,

How do I make a directory Treeview populate the sub-folder and files?
I have a project folder, then in my project folder I have sub-folders.

I would like a way to:
Use Treeview
Show root folder
show sub-folder
show sub-folder files ( Which are shortcut links to Windows Desktop Items)
ability to click on shortcut item and it launch the item

I can get the project folder>Shortcut-Folder to open in root folder and I see all sub-folders
but I have not figured out how to get drilled down into sub-folders.

I would like to be able to in Treeviw to drill all the way down to desired shortcut item and launch it.

Currently it is just popping open folder explorer view of root folder with view of all sub folders.
Thank You,

Wayne

User avatar
brittneyr
Site Admin
Posts: 197
Joined: Thu Jun 01, 2017 7:20 am

Re: How do I make a directory Treeview populate the sub-folder and files?

Post by brittneyr » Mon Jun 10, 2019 7:38 am

[TOPIC MOVED TO POWERSHELL GUI BY MODERATOR]
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13810
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How do I make a directory Treeview populate the sub-folder and files?

Post by jvierra » Mon Jun 10, 2019 8:02 am

Add this to the load event:

$treeviewNav.Nodes.Add('C:\','c:\')

And add this the to the "$treeviewNav_AfterSelect" event:

Code: Select all

    $node = $_.Node
	Get-ChildItem $node.Text -Directory |
        ForEach-Object{
            $node.Nodes.Add($_.FullName, $_.FullName)
        }
    $node.Expand()

Locked