Datagridview search

Ask your Windows 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.
Locked
User avatar
nirmalks
Posts: 30
Joined: Sun Aug 02, 2015 10:01 am

Datagridview search

Post by nirmalks » Sun Aug 16, 2015 10:49 am

Hi All,

I have a datagridview control on form. I am using below code to import a CSV:

$rows = Import-Csv .\Data.CSV -Header Data1, Data2, Data3
$table = ConvertTo-DataTable -InputObject $rows
Load-DataGridView -DataGridView $datagridview1 -Item $table

I have created a textbox and added TextChangedEvent. How can I search through datagridview? I should be able to search anywhere in Datagridview.

Thank You,
Nratawa

User avatar
SAPIEN Support Forums
Posts: 945
Joined: Wed Dec 03, 2014 2:26 pm

Datagridview search

Post by SAPIEN Support Forums » Sun Aug 16, 2015 10:49 am

This is an automated post. A real person will respond soon.

Thank you for posting, nirmalks.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***

User avatar
nirmalks
Posts: 30
Joined: Sun Aug 02, 2015 10:01 am

Re: Datagridview search

Post by nirmalks » Sun Aug 16, 2015 9:14 pm

nirmalks wrote:Hi All,

I have a datagridview control on form. I am using below code to import a CSV:

$rows = Import-Csv .\Data.CSV -Header Data1, Data2, Data3
$table = ConvertTo-DataTable -InputObject $rows
Load-DataGridView -DataGridView $datagridview1 -Item $table

I have created a textbox and added TextChangedEvent. How can I search through datagridview? I should be able to search anywhere in Datagridview.

Thank You,
Nratawa
Hello,

Anyone please?

Thanks,
Nratawa

jvierra
Posts: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview search

Post by jvierra » Sun Aug 16, 2015 9:30 pm

You can enumerate the rows and cells collections.

User avatar
nirmalks
Posts: 30
Joined: Sun Aug 02, 2015 10:01 am

Re: Datagridview search

Post by nirmalks » Mon Aug 17, 2015 10:34 am

jvierra wrote:You can enumerate the rows and cells collections.
Can you please post a little example in a ForEach loop?

jvierra
Posts: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview search

Post by jvierra » Mon Aug 17, 2015 10:40 am

Start with the help. Look closely at all examples.

help about_foreach

User avatar
nirmalks
Posts: 30
Joined: Sun Aug 02, 2015 10:01 am

Re: Datagridview search

Post by nirmalks » Mon Aug 17, 2015 12:34 pm

jvierra wrote:Start with the help. Look closely at all examples.

help about_foreach
Well, I'm very much aware of ForEach loop, but don't know what code to put inside it.

{
What Code to put in here??
}

How do I use below code in PowerShell?

if (row.Cells[row.Index].Value.ToString().Equals(searchValue))

Thanks,
Nratawa

jvierra
Posts: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview search

Post by jvierra » Mon Aug 17, 2015 1:31 pm

PowerShell Code
Double-click the code block to select all.
$datagridview.Rows | 
    ForEach-Object{
        $_.Cells|
        ForEach-Object{
            $_.Value -eq 'SomeValue'
        }
     }

User avatar
nirmalks
Posts: 30
Joined: Sun Aug 02, 2015 10:01 am

Re: Datagridview search

Post by nirmalks » Mon Aug 17, 2015 3:24 pm

jvierra wrote:
PowerShell Code
Double-click the code block to select all.
$datagridview.Rows | 
    ForEach-Object{
        $_.Cells|
        ForEach-Object{
            $_.Value -eq 'SomeValue'
        }
     }
Great!! and thank you! you saved my day!

-Best

jvierra
Posts: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview search

Post by jvierra » Mon Aug 17, 2015 3:46 pm

You can also do it by column if you choose the column.

Locked