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.
User avatar
angelofstealth
Posts: 67
Joined: Wed Feb 13, 2013 4:26 pm

Treeview - Node - Property (Plus/Minus)

Post by angelofstealth » Thu Mar 07, 2019 11:55 am

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.  
  3. $n.Name = $key
  4.  
  5. $n.Text = $nodeName
  6.  
  7. $n.ImageIndex = 0
  8.  
  9. $n.SelectedImageIndex = 0
  10.  
  11. $treeview.Nodes.Add($n)

jvierra
Posts: 13952
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Mar 07, 2019 12:52 pm

The attached PSF will explain it all.
Attachments
Demo-TreeviewFolders.psf
(31.52 KiB) Downloaded 28 times

jvierra
Posts: 13952
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Mar 07, 2019 12:58 pm


User avatar
angelofstealth
Posts: 67
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Thu Mar 07, 2019 1:03 pm

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: 67
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Thu Mar 07, 2019 1:28 pm

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: 13952
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Mar 07, 2019 1:46 pm

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: 67
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Thu Mar 07, 2019 1:56 pm

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: 13952
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Mar 07, 2019 2:05 pm

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: 67
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Thu Mar 07, 2019 2:23 pm

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: 13952
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Mar 07, 2019 2:54 pm

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.

Locked