0

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

2
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by Pgmer
0

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

0
 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

0
 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 by Pgmer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.