Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filter each cell in dgv
I have the datagridview on my form and i want to filter it for current text in textbox1.

Example i have fields

And if i enter in textbox1 value "John" i need to check each of those columns does any contain a value John and show on dgv.

More about me on

How is the data in the DataGridView stored? Is it stored using a DataSource or simply being directly added into the DataGridView? If you're using a datasource, filtering becomes fairly easy, as you can do something like this:

CType(dgv.DataSource, DataTable).DefaultView.RowFilter = TextBox1.Text

If you're just inputting things in the Data Grid View direclty, I think you will need to go through every row, check to see if the column is equal to the textbox value, and eliminate those that are not equivalent.
My Blog | My Setup | My Videos | Have a wonderful day.
I'm inputting it directly on DGV by using SQL Query. After i get the data by using sql query data was in dataset. After i use dgv source to get the data from dataset to dgv.

But the problem would be when i enter two values in textbox1.text. In that case i need result which contains in two columns those values.

ex: Bran Prod

It should give me result where it contains Name & location or any other two columns.
More about me on

Ah, okay.. You're probably looking for something like this:

Please note that this is Pseudocode, because I do not know the official syntax of VB.NET DGV offhand:

dvg.SelectionMode = FullRowSelect
For Each Row as DataGridViewRow in dvg.Rows
    For Each Cell as DataGridViewCell in Row.Cells
        If (Cell.Value.ToString().Equals(TextBox1.Text))
            Row.Selected = True
        End If

This should check all of the cells for the values being searched and select only the rows containing that information.
My Blog | My Setup | My Videos | Have a wonderful day.

I wanted to add a small remark:
Break is VB code, the equivalent in VB.NET is Exit

In this case it would be Exit For, but you can use it in a lot of situations:
  • Exit For
  • Exit Do
  • Exit While
  • Exit Function
  • Exit Sub

Forum Jump:

Users browsing this thread: 1 Guest(s)