$Treeview focus

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 2 years and 3 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
mkaur2505
Posts: 6
Last visit: Mon Dec 06, 2021 2:14 pm
Has voted: 1 time

$Treeview focus

Post by mkaur2505 »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: Sapien PowerShell Studio, 2021
Operating system: Windows
PowerShell version(s):
32-bit version of software? yes

*** Please add details and screenshots as needed below. ***
Hi I have a code which shows a list in expanded view using Treeview.ExpandAll(). Using this, the focus goes to the bottom of the list. Is there a way I can show it to top of the list without selecting any nodes?

DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
by jvierra » Sun Nov 28, 2021 8:49 pm
Again, start with the docs. You can clear a set object by assigning the object reference to "$null"
Go to full post
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: $Treeview focus

Post by jvierra »

  1. # Move focus to the first root node.
  2. $treeList1.FocusedNode = $treeList1.Nodes[0]
mkaur2505
Posts: 6
Last visit: Mon Dec 06, 2021 2:14 pm
Has voted: 1 time

Re: $Treeview focus

Post by mkaur2505 »

Hi,

I get the below error:
The property 'FocusedNode' cannot be found on this object. Verify that the property exists and can be set. I have used the code after $treelist1.expandall()
mkaur2505
Posts: 6
Last visit: Mon Dec 06, 2021 2:14 pm
Has voted: 1 time

Re: $Treeview focus

Post by mkaur2505 »

Tried the below code and it works:
$treeview1.SelectedNode = $treeview1.Nodes[0]

But it pre selects the list value as the top of the tree. This is a mandatory field on my form and pre selecting the value defeats the purpose of making user enter this value. Is there a way I can keep the focus on top of the tree without selecting a value from the list?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: $Treeview focus

Post by jvierra »

Again, start with the docs. You can clear a set object by assigning the object reference to "$null"
mkaur2505
Posts: 6
Last visit: Mon Dec 06, 2021 2:14 pm
Has voted: 1 time

Re: $Treeview focus

Post by mkaur2505 »

Thanks Heaps!
This works perfect and fulfills what we require.

For anyone else interested in the code:

$treeList.ExpandAll()
$treeList.SelectedNode = $treeList.Nodes[0]
$treeList.SelectedNode = $null
This topic is 2 years and 3 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