TreeView expand and focus on searched for node

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 1 year and 7 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
NewRootUsr
Posts: 11
Last visit: Thu Apr 11, 2024 5:57 am

TreeView expand and focus on searched for node

Post by NewRootUsr »

I have figured out how to search for a node based on text that is input, however it appears to expand every single node even if the found node is only 1 level down. I am searching for a way that it will only expand the tree path where the node is found and nothing else.

Has anyone done this before? The searching is done top down, and there is roughly 6 levels of my tree, but if a node is found at level 2 I wish for it to only expand what is needed if that makes sense.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TreeView expand and focus on searched for node

Post by jvierra »

Not enough info to know what you are doing. You can search for a node by name, text or path and just set teh expanded property of that node to true and that node and all parent nodes will expand. There is no way to expand a child node and not expand the parent node which actually makes no sense.

Without more info it is unclear what you are trying to accomplish or how you are searching and expanding.
NewRootUsr
Posts: 11
Last visit: Thu Apr 11, 2024 5:57 am

Re: TreeView expand and focus on searched for node

Post by NewRootUsr »

jvierra wrote: Tue Aug 23, 2022 12:56 pm Not enough info to know what you are doing. You can search for a node by name, text or path and just set teh expanded property of that node to true and that node and all parent nodes will expand. There is no way to expand a child node and not expand the parent node which actually makes no sense.

Without more info it is unclear what you are trying to accomplish or how you are searching and expanding.
You actually answered my question with just expanding the child node I am after when searching. We're working on building out a treeview for active directory but we need to be able to search for accounts and then display where that account is within the tree, what OU's it is under etc, but without expanding every OU unrelated to the found node.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TreeView expand and focus on searched for node

Post by jvierra »

Why do that. Every AD object has all of that in its name. You know that as the "DistinguishedName" and that has the whole path in the correct order. Just use that. No need to search for anything.

You can use ADSI to convert the DN or RDN to and from aDSPath strings.

https://docs.microsoft.com/en-us/window ... ap-adspath

Here is an older example that gives some of the techniques. It is simple but gives an easier approach to working with AD objects.
Attachments
Demo-ADSITreeView.psf
(23.67 KiB) Downloaded 49 times
This topic is 1 year and 7 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