Querying DataGridView

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
User avatar
Posts: 55
Last visit: Tue Jun 22, 2021 9:24 am

Querying DataGridView

Post by supportMIB »

I have a datagrid view that is populated with:

Code: Select all

$Global:coll = (Get-ADUser -filter * -Properties PasswordNeverExpires, passwordlastset, lastlogon, enabled | select Name, Enabled, PasswordNeverExpires, PasswordLastset, @{ name = "LastLogon"; Expression = ({ get-date $_.lastlogon -UFormat "%D %R" }) })

Update-DataGridView $datagridview6 $coll
This populates it with all of our AD users, with their username, enabled status etc...

I have a group box that contains several checkboxes such as:
[ ] Non-Expiring Accounts (this would slim the datagridview to just showing non-expiring accounts)
[ ] Older than 90 days (this would display accounts older than 90 days)

My issue with this is when I click Non expiring password box, it slims down the list to only show those, but what if i wanted to see non expiring AND older than 90 days?

What is the best way to achieve this?

Should I have it show non expiring, then re-query the orignal data (stored in $coll) and add that to the datagridview then remove duplicates?

Any suggestions would be appreciated
Posts: 15052
Last visit: Wed Jan 26, 2022 2:55 pm
Answers: 17
Has voted: 3 times
Been upvoted: 13 times

Re: Querying DataGridView

Post by jvierra »

To filter on multiple criteria you will need to use a DataTable and set the "RowFilter" property of the "DefaultDataView". Use your search engine to find examples of using the "DefaultDataView.RowFilter" property.