Tips for using RowFilter property

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 2 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
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Tips for using RowFilter property

Post by mattys »

On Form Load-
I'm importing a csv using Import-Csv and assign to variable $csv

I then use a DataGridView and convertTo-Datable
  1. $datagridview.DataSource = ConvertTo-DataTable $CSV
The datagrideview displays correctly.

Then Im attempting to Filter using checkboxes and trigger using a 'Filter' button.

  1. $buttonFilter_Click={
  2.    
  3.     if ($checkboxMedium.Checked -eq $true)
  4.     {
  5.         $r =  $CSV | ? { $_.Impact -eq 'Medium' }
  6.        
  7.         $datagridview.DataSource.DefaultView.RowFilter = $r
  8.     }
  9. }
Im running into error that a RowFilter is not a property?.
Where am I missing?

Thank you in advance
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tips for using RowFilter property

Post by jvierra »

You cannot use a collection as a filter. A RowFilter is a SQL filter clause stated as a string. I.E. "Impact = 'Medium'"

The following gives the "RowFilter" syntax.
https://www.csharp-examples.net/dataview-rowfilter/
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Tips for using RowFilter property

Post by mattys »

OK thanks for clarifying the RowFilter property.

Can I ask, what is most efficient way to filter a DatagridView?

I would like to go through each checkbox and determine which is in a checked state.
Image
https://imgshare.io/image/capture.rwfq5Y
This topic is 2 years and 2 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