Grid search output

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 6 years and 9 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
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Grid search output

Post by sekou2331 »

Product, version and build:
Powershell Studio 2017 version:5.4.140
64 bit version
Operating system: Windows 7
64 bit OS
PowerShell Version: 5
---------------------------------------

Hi,

I am using the built-in Winform Template Full Grid Search Template. It works but what I need it to do is when I search only show in the grid what I am searching for not just take me to the place in grid where the item I am searching is. How and where should I make that change.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid search output

Post by jvierra »

You would use a datatable to load the grid and set the filter on the table based on the requested text.
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Grid search output

Post by sekou2331 »

Can you please give me an example. There are a lot of premade functions. I understand some of it but not all. I tried the below

  1. $formMain_Load= {
  2. $UsersComputers = import-csv Computer.csv
  3.     $importData = $UsersComputers | sort-object -Property IPAddress, ComputerName, Username, LastBootTime, City, SoftwareName, SoftwareVersion -Unique
  4.    
  5.     $table = ConvertTo-DataTable -InputObject $importData -FilterWMIProperties
  6.     Update-DataGridView -DataGridView $datagridviewResults -Item $table -AutoSizeColumns DisplayedCells
  7. }
  8.  
  9. $buttonSearch_Click={
  10.     $SearchTable = SearchGrid
  11.     $table = ConvertTo-DataTable -InputObject $SearchTable -FilterWMIProperties
  12.     Update-DataGridView -DataGridView $datagridviewResults -Item $table -AutoSizeColumns DisplayedCells
  13. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid search output

Post by jvierra »

In the search grifd form the grid is already bound to a table so just use the "RowFilter" to return the rows wanted.

Example:
  1. $textboxSearch_KeyUp=[System.Windows.Forms.KeyEventHandler]{
  2. #Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
  3.     if($_.KeyCode -eq 'Enter' -and $buttonSearch.Enabled){
  4.         if($textboxSearch.Text){
  5.             $datagridviewResults.DataSource.DefaultView.RowFilter = "ProcessName LIKE '*$($textboxSearch.Text)*'"
  6.                }
  7.            $_.SuppressKeyPress = $true
  8.     }
  9. }
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Grid search output

Post by sekou2331 »

How does this re-populate the datagrid with what I searched for in the text box. I am trying to understand how to re populate the grid with what is in the search box and only.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid search output

Post by jvierra »

It filters the grid and display only the filtered items automatically. Once the filter is set the grid shows only rows matching the filter.
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Grid search output

Post by sekou2331 »

I see what you are saying now. Last question. How can I filter off of multiple columns. I tried the below.

  1. if($_.KeyCode -eq 'Enter' -and $buttonSearch.Enabled)
  2.     {
  3.         if ($textboxSearch.Text)
  4.         {
  5. ($datagridviewResults.DataSource.DefaultView.RowFilter = "ProcessName LIKE '*$($textboxSearch.Text)*'") -or
  6. ($datagridviewResults.DataSource.DefaultView.RowFilter = "SoftwareName LIKE '*$($textboxSearch.Text)*'")
  7.      }
  8. }
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Grid search output

Post by sekou2331 »

Forget I figured it out. Many thanks for the help!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid search output

Post by jvierra »

The filter is a SQL "WHERE" clause so just use SQL syntax to build your filter.
This topic is 6 years and 9 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