I want to filter the datagridview on Search button click,i am using 3-tier architecture,the grid should be updated with the search result

you need to use dataview and filter the dataview with dataview.rowfilter method and bind the result back to the grid.

 For i = 0 To (GrdUnitsOfMeasure.RowCount - 2)
                For j = 0 To (GrdUnitsOfMeasure.ColumnCount - 1)
                    If (GrdUnitsOfMeasure.Rows(i).Cells(j).Value.ToString.ToLower.StartsWith(TxtSearch.Text)) Then
                        GrdUnitsOfMeasure.Rows(i).Cells(j).Style.BackColor = Color.Red
                     else
                     MessageBox.Show("No Records Found")
                     EndIf
                     Next
                     Next

I want to highlight only the content

 Try
            Dim cn As SqlConnection
            Dim strCnn As String = "Your data base connection string"
            cn = New SqlConnection(strCnn)
            cn.Open()
            Dim comm As New SqlCommand("Your sp or Command text to get the data from DB", cn)
            '' If ur using Sp then Commandtype= CommandType.StoredProcedure if it is Text then comm.CommandType=CommandType.Text
            comm.CommandType = CommandType.StoredProcedure
            Dim da As New SqlDataAdapter(comm)
            Dim ds As New DataSet
            da.Fill(ds)

            Dim dv As New DataView
            dv = dsNew.Tables(0).DefaultView
            dv.RowFilter = "Name = '" & "John" & "'"

            ''Close your connections and commands.
        Catch ex As Exception
            ''Handle error if any
        End Try

try something like this code.
Note:Code above is not tested. You need to change the filter criteria to your need.

Edited 4 Years Ago by Pgmer

This article has been dead for over six months. Start a new discussion instead.