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

Example i have fields
Name,Lastname,Location,Town,Address.

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.

Anel
More about me on tSoftwares.net

Reply
#2
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:


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

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.
Reply
#3
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 tSoftwares.net

Reply
#4
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:

Code:
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
            Break
        End If
     Next
Next


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.
Reply
#5
Hi,

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)