display only specific rows in datagridview

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 3 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
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

display only specific rows in datagridview

Post by Domtar »

hi all,

I have a GUI where a datagridview shows all installed updates on a computer.

I'm trying to add a filter textbox that will hide all rows where the filter's content will not appear.

so if someone put KB366 in that filter textbox, i wish to display only the KB that start with 366.

how can I accomplish that?

Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: display only specific rows in datagridview

Post by jvierra »

This can be don e using a DataTable and setting the RowFilter property of the DefaultDataView.
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

Re: display only specific rows in datagridview

Post by Domtar »

got it!

this does what i need :-)

for ($i = 0; $i -lt $dataInstUpdates.RowCount; $i++)
{
if ($dataInstUpdates.Rows[$i].Cells[0].value -notlike "KB$($textboxFilterUpdate.text)*")
{ $dataInstUpdates.Rows[$i].Visible = $false }
else
{ $dataInstUpdates.Rows[$i].Visible = $true }
}

thanks!
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: display only specific rows in datagridview

Post by Lembasts »

Might be easier to do :
$datagridview.datasource.defaultview.rowfilter = "<valuename> -notlike 'KB$($textboxFilterUpdate.text)*'"
...assuming the datasource is a datatable.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: display only specific rows in datagridview

Post by jvierra »

Lembasts wrote: Wed Jun 10, 2020 5:18 pm Might be easier to do :
$datagridview.datasource.defaultview.rowfilter = "<valuename> -notlike 'KB$($textboxFilterUpdate.text)*'"
...assuming the datasource is a datatable.
That is what I tried to tell you above.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: display only specific rows in datagridview

Post by Lembasts »

You've already told me :-)
Im telling them.
That's another reason I use dgvs over checkedlistboxes - the rowfilter is awesome!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: display only specific rows in datagridview

Post by jvierra »

Again - you are missing the big picture. The RowFilter works on a ListBox too.

If you start with "System.Windows.Forms.Control you will learn how all of these things work. By guessing you will be constantly doing things the hard way.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: display only specific rows in datagridview

Post by Lembasts »

Whilst the Microsoft Docs are a great resource they are lousy at teaching stuff for beginners.
If one could learn everything from the MS docs then one wouldnt need forums like this or stackoverflow etc...
And Sapien shouldnt have to offer classroom training...
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: display only specific rows in datagridview

Post by jvierra »

You need to read the training documents and not just the control documents.
https://docs.microsoft.com/en-us/dotnet ... dows-forms

And you have to actually study and understand what teh teaching material is trying to show you.
This topic is 3 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