Treeview - Node - Property (Plus/Minus)

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 5 years and 2 weeks 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
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Treeview - Node - Property (Plus/Minus)

Post by angelofstealth »

Is there a way to force or add a property to add the ShowPlusMinus to a treeview node? Example code below, works fine as far as loading in the objects in the treeview and clicking down through the treeview. Just none of my dropdowns will have Plus or Minus, the property is set by default to true and i have even code it on the treeview. No change. Treeview events are being loaded by NodeMouseClick to populate the treeview cascading, but without Plus Minus. I know I could detect for child items, just dont know how to force the property to have the plus/minus.
  1. $n = New-Object System.Windows.Forms.TreeNode
  2. $n.Name = $key
  3. $n.Text = $nodeName
  4. $n.ImageIndex = 0
  5. $n.SelectedImageIndex = 0
  6. $treeview.Nodes.Add($n)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Treeview - Node - Property (Plus/Minus)

Post by jvierra »

The attached PSF will explain it all.
Attachments
Demo-TreeviewFolders.psf
(31.52 KiB) Downloaded 159 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Treeview - Node - Property (Plus/Minus)

Post by jvierra »

User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: Treeview - Node - Property (Plus/Minus)

Post by angelofstealth »

Is there not a way to add the show plus/minus on adding the node vs on click? As with the psf attached my code is doing the same thing by showing the dropdown/plus after a click and not when the nodes are added.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: Treeview - Node - Property (Plus/Minus)

Post by angelofstealth »

I think i am going to adjust the way i load in the values with the node mouse click. Appreciate the help , should be good from here.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Treeview - Node - Property (Plus/Minus)

Post by jvierra »

The plus/minus is added automatically if the property is set to true. The demo just shows how to turn it on and off.

Carefully read all of the link I posted.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: Treeview - Node - Property (Plus/Minus)

Post by angelofstealth »

I agree it should be added automatically, i stated that in my first message.

In your attached psf, if I change the form property showplusminus from false (what is was) to true and run the code. It does not show a plus symbol on my end for C:\.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Treeview - Node - Property (Plus/Minus)

Post by jvierra »

Initially there are no child nodes under the root. After you click it there are and the p/m will show. The +- only shows whn there ae child nodes.

Please read the link carefully. All of the rules are spelled out.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: Treeview - Node - Property (Plus/Minus)

Post by angelofstealth »

For the childnodes loaded after the click, these childnodes that have childnodes don't show having plus/minus. Only after clicking the childnodes will the next childnodes show is the point i am trying to make. Instead of clicking the parent node, load childnodes and display childnodes that have childnodes below them. Which is why i was looking for a property to set as I have no issues creating the treeview/nodes under eachother with other properties.

I will take a look at the link, just stating the psf provided is doing the same thing my code is doing which is not displaying childnodes (plus/minus) under childnodes after root/parent is clicked.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Treeview - Node - Property (Plus/Minus)

Post by jvierra »

Because the nodes are only loaded if you have clicked them. That is the behavior of an incremental load. The code was written to demonstrate an incremental load and not to demo the +-. Click on all nodes until all are loaded then use the +- and all loaded nodes with loaded children will behave as you want.
This topic is 5 years and 2 weeks 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