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.
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
shiroscout
Posts: 41
Last visit: Sat Jul 15, 2023 7:13 pm

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

Post by shiroscout »

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: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 times

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

Post by brittneyr »

[TOPIC MOVED TO POWERSHELL GUI BY MODERATOR]
Brittney
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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()
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked