954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

highlight datagrid rows upon searching

hi everyone i need bit of support in my vb coding. i've publish data onto a datagrid(in vb express 2010). i just want to highlight entire row once the search data is found(in lime color) and color should be remain in that particular row when searching next records. so that user would easily know which records are searched and which are not by looking @ the color. any help. thanks in advance.

docgrid
Newbie Poster
9 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

See if this helps.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        searchDGV(TextBox1.Text)
    End Sub
    Sub searchDGV(ByVal selSearch As String)
        With DataGridView1
            Dim iTemp As Integer = 1
            If .AllowUserToAddRows Then iTemp = 2 '// check if extra row or not, at bottom of dgv.
            For i As Integer = 0 To .Rows.Count - iTemp '// loop thru all rows.
                For x As Integer = 0 To .Columns.Count - 1 '// loop thru all columns in a row.
                    If .Item(x, i).Value = selSearch Then '// locate your search.
                        .Rows(i).DefaultCellStyle.BackColor = Color.Lime
                    End If
                Next
            Next
        End With
    End Sub
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

Thanks code order. i managed to find a solution and your solution seems rather easy to use. great :)

docgrid
Newbie Poster
9 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: