title: Searching between TreeView Nodes Powershell
body: <p><strong>TLDR: Use treeview to search network folders and show results in trees path.</strong></p>
  <p>I have a tool at work that is outdated and needs to be updated, but the source was lost, so I have been rebuilding it. This is the only thing I am struggling with recreating.</p>
  <p>In Powershell ISE having a Tree View be searchable, that updates with $textbox.add_textchanged as you type to find matched text.</p>
  <p>Here is an example:</p>
  <p><a href="https://i.stack.imgur.com/SBcMn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SBcMn.png" alt="enter image description here" /></a></p>
  <pre><code>
  function Product-Function{
  $Product.add_textchanged{
  #idk what im doing
                          }
                           }
  
  $Product                          = New-Object system.Windows.Forms.TextBox
  $Product.multiline                = $false
  $Product.CharacterCasing          = &quot;Upper&quot;
  $Product.width                    = 235
  $Product.height                   = 20
  $Product.location                 = New-Object System.Drawing.Point(20,20)
  $Product.Font                     = $MainFont
  $Product.Text                     = &quot;&quot;
  Product-Function
  
  $TreeView                         = New-Object System.Windows.Forms.TreeView
  $TreeView.Location                = New-Object System.Drawing.Point(20, 55)
  $TreeView.Size                    = New-Object System.Drawing.Size(540, 320)
  
  $WinNode                          = New-Object System.Windows.Forms.TreeNode
  $WinNode.text                     = &quot;Windows&quot;
  $WinNode.name                     = &quot;Windows&quot;
  [void]$TreeView.Nodes.Add($WinNode).FullPath
  
  $WinCommonNode                    = New-Object System.Windows.Forms.TreeNode
  $WinCommonNode.text               = &quot;Common&quot;
  $WinCommonNode.name               = &quot;Common&quot;
  [void]$WinNode.Nodes.Add($WinCommonNode)
  
  $WinCommonNCNode                  = New-Object System.Windows.Forms.TreeNode
  $WinCommonNCNode.text             = &quot;Non_Certified&quot;
  $WinCommonNCNode.name             = &quot;Non_Certified&quot;
  [void]$WinCommonNode.Nodes.Add($WinCommonNCNode)
  
  $WinLicensedNode                  = New-Object System.Windows.Forms.TreeNode
  $WinLicensedNode.text             = &quot;Licensed&quot;
  $WinLicensedNode.name             = &quot;Licensed&quot;
  [void]$WinNode.Nodes.Add($WinLicensedNode)
  
  $WinLicensedNCNode                = New-Object System.Windows.Forms.TreeNode
  $WinLicensedNCNode.text           = &quot;Non_Certified&quot;
  $WinLicensedNCNode.name           = &quot;Non_Certified&quot;
  [void]$WinLicensedNode.Nodes.Add($WinLicensedNCNode)
  
  $WinRestrictedNode                = New-Object System.Windows.Forms.TreeNode
  $WinRestrictedNode.text           = &quot;Restricted&quot;
  $WinRestrictedNode.name           = &quot;Restricted&quot;
  [void]$WinNode.Nodes.Add($WinRestrictedNode)
  
  $WinRestrictedNCNode              = New-Object System.Windows.Forms.TreeNode
  $WinRestrictedNCNode.text         = &quot;Non_Certified&quot;
  $WinRestrictedNCNode.name         = &quot;Non_Certified&quot;
  [void]$WinRestrictedNode.Nodes.Add($WinRestrictedNCNode)
  
  
  #macs
  
  $MacNode                          = New-Object System.Windows.Forms.TreeNode
  $MacNode.text                     = &quot;Macaroni&quot;
  $MacNode.name                     = &quot;Macaroni&quot;
  $Macaroni                         = &quot;\\NetworkLocation\Macintosh&quot;
  [void]$TreeView.Nodes.Add($MacNode).FullPath
  
  #=======================================================================================================================
                                                    #File Paths#
  #=======================================================================================================================
  $WinCommon = &quot;\\NetworkLocation\DesktopServices\Common&quot;
  $WinLicensed = &quot;\\NetworkLocation\DesktopServices\Licensed&quot;
  $WinRestricted = &quot;\\NetworkLocation\DesktopServices\Restricted&quot;
  $WinCommonNC = &quot;\\NetworkLocation\DesktopServices\Common\_Non-Certified&quot;
  $WinLicensedNC = &quot;\\NetworkLocation\DesktopServices\Licensed\_Non-Certified&quot;
  $WinRestrictedNC = &quot;\\NetworkLocation\DesktopServices\Restricted\_Non-Certified&quot;
  
  #=======================================================================================================================
  
  $array                            = @(Get-ChildItem -Path $WinCommon)
     foreach ( $obj in $array ) {
  $WCNode                           = New-Object System.Windows.Forms.TreeNode
  $WCNode.text                      = $obj
  [void]$WinCommonNode.Nodes.Add($WCNode).FullPath
       }
  $array                            = @(Get-ChildItem -Path $WinLicensed)
     foreach ( $obj in $array ) {
  $WLNode                           = New-Object System.Windows.Forms.TreeNode
  $WLNode.text                      = $obj
  [void]$WinLicensedNode.Nodes.Add($WLNode).FullPath
       }
  $array                            = @(Get-ChildItem -Path $WinRestricted)
     foreach ( $obj in $array ) {
  $WRNode                           = New-Object System.Windows.Forms.TreeNode
  $WRNode.text                      = $obj
  [void]$WinRestrictedNode.Nodes.Add($WRNode).FullPath
       }
  
  $array                            = @(Get-ChildItem -Path $WinCommonNC)
     foreach ( $obj in $array ) {
  $WCNCNode                         = New-Object System.Windows.Forms.TreeNode
  $WCNCNode.text                    = $obj
  [void]$WinCommonNCNode.Nodes.Add($WCNCNode).FullPath
       }
  $array                            = @(Get-ChildItem -Path $WinLicensedNC)
     foreach ( $obj in $array ) {
  $WLNCNode                         = New-Object System.Windows.Forms.TreeNode
  $WLNCNode.text                    = $obj
  [void]$WinLicensedNCNode.Nodes.Add($WLNCNode).FullPath
       }
  $array                            = @(Get-ChildItem -Path $WinRestrictedNC)
     foreach ( $obj in $array ) {
  $WRNCNode                         = New-Object System.Windows.Forms.TreeNode
  $WRNCNode.text                    = $obj
  [void]$WinRestrictedNCNode.Nodes.Add($WRNCNode).FullPath
       }
  
       #mac stuff
  
  $array                            = @(Get-ChildItem -Path $Macaroni)
     foreach ( $obj in $array ) {
  $SubMac                           = New-Object System.Windows.Forms.TreeNode
  $SubMac.text                      = $obj
  [void]$MacNode.Nodes.Add($SubMac).FullPath
       }
  #======================================================================================================================= 
  </code></pre>
  <p><strong>So my question is, How can I make my textbox filter all of the items within nodes, for match namees, and show where it is within the nodes</strong></p>
  <p>The reason we have this tool, is we have hundreds of software installs in these folders and this tool makes it easy to search for the exact location. It was made in the past and I just need to remake it, but I can not figure out how to filter the pulled data of the nodes.</p>
  <p>================== Everything above has been answered.</p>
  <p>Additional question.
  Is there a way to hide extra non matched items and shrink nodes that do not have any matches. Our old tool does, and it makes it way easier to read the location.
  <a href="https://i.stack.imgur.com/9MZdL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9MZdL.jpg" alt="enter image description here" /></a></p>
  <p>old tool on the left, my new tool on the right.</p>