Vscrollbar in Treeview

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
daniel kusnir
Posts: 27
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Thu May 25, 2017 8:22 am

Vscrollbar in Treeview

Post by daniel kusnir »

Hello

does anybody know how custom Vscroll can be used for scrolling down the Treeview full of nodes and childnodes ? i can use it only when i have a nodes, but unfortunatelly it does not work when childnodes are there.
my simple code :
  1. $vscrollbar1_Scroll = [System.Windows.Forms.ScrollEventHandler]{
  2.  
  3.    
  4.  
  5.     $treeview1.TopNode = $treeview1.Nodes[$vscrollbar1.Value]
  6.  
  7.    
  8.  
  9. }
thanks

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

Re: Vscrollbar in Treeview

Post by jvierra »

Why? The TreeView has its own scrollbars. They will turn on when needed. To be sure the children are expanded use the "ExpandAll" method of the tree control.

$treeview1.ExpandAll()

User avatar
daniel kusnir
Posts: 27
Joined: Thu May 25, 2017 8:22 am

Re: Vscrollbar in Treeview

Post by daniel kusnir »

because i have 2 treeviews and want to create 1 VSBar to scroll them both. similar to text comparators, i need to build treeview comparator

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

Re: Vscrollbar in Treeview

Post by jvierra »

Ok. Just send scroll commands to both TreeView controls. You can send scroll commands by scroll position and the two will track with the control.

User avatar
daniel kusnir
Posts: 27
Joined: Thu May 25, 2017 8:22 am

Re: Vscrollbar in Treeview

Post by daniel kusnir »

to be honest, i have been trying to implement this approach as well, but without luck - it seems even more complicated. Can you give me some example or some working code ?

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

Re: Vscrollbar in Treeview

Post by jvierra »

Sorry - I don't have any samples.

User avatar
daniel kusnir
Posts: 27
Joined: Thu May 25, 2017 8:22 am

Re: Vscrollbar in Treeview

Post by daniel kusnir »

figured it out. what you suggested is very complicated. turns out solution is super simple

1. create an array and assign custom index to each value
2. compare scroll value to custom index value
3. set selectednode to node that contains this custom index
4. create afterselect event and set topnode as selected node

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

Re: Vscrollbar in Treeview

Post by jvierra »

Oh. I thought you were asking how to synchronize the scroll bars. You are just trying to select the nodes.

To select nodes you don't need an array. Just select the nodes as they occur in the tree by getting the direction of scroll.

User avatar
daniel kusnir
Posts: 27
Joined: Thu May 25, 2017 8:22 am

Re: Vscrollbar in Treeview

Post by daniel kusnir »

that is correct - i needed to sync the scrollbars. And this is only solution i came up in order not to do any heavy coding.
As i do not know how to scroll to child, i simply select that child that has same index as vscrollbar and make it appear on top.But no matter the path, result works 100 % percent. Too bad i cannot simply attach the solution

gugyhodge
Posts: 1
Joined: Thu Jan 23, 2020 1:18 am

Re: Vscrollbar in Treeview

Post by gugyhodge »

I did not like the gray style of their ScrollBars vertical and horizontal. Is it possible to change it somehow, I want gradient ScrollBars. How can I do that and how to learn precalculus fast?

Locked