Hello

I am trying to change background color of rows in datagridview having same data with this code but am not getting desired results. Can anyone please help?

Code:
Private Sub DataGridView2_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView2.CellFormatting
        For i = 0 To DataGridView2.Rows.Count - 1
            If i > 0 And i < DataGridView2.Rows.Count Then
                If DataGridView2.Rows(i).Cells(0).Value = DataGridView2.Rows(i - 1).Cells(0).Value Then
                    DataGridView2.Rows(i).DefaultCellStyle.BackColor = Color.WhiteSmoke
                Else
                    DataGridView2.Rows(i).DefaultCellStyle.BackColor = Color.LightGray
                End If
            End If
        Next
    End Sub
Thanks