Try something like:
Dim last_value As String = ""
Dim last_color As Color = Color.LightBlue
If DataGridView1.Rows.Count > 0 Then
For Each row In DataGridView1.Rows
If DataGridView1.Item("houseno", row.index).Value <> last_value Then
If last_color = Color.LightBlue Then
DataGridView1.Rows(row.index).DefaultCellStyle.BackColor = Color.LightGray
Else
DataGridView1.Rows(row.index).DefaultCellStyle.BackColor = Color.LightBlue
End If
Else
DataGridView1.Rows(row.index).DefaultCellStyle.BackColor = last_color
End If
If DataGridView1.Rows(row.index).IsNewRow = False Then
last_value = DataGridView1.Item("houseno", row.index).Value.ToString
last_color = DataGridView1.Rows(row.index).DefaultCellStyle.BackColor
End If
Next
End If
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Make all cells in row 1 blue.
For Each c As DataGridViewCell In DataGridView1.Rows(1).Cells
c.Style.BackColor = Color.Blue
Next
Reverend Jim
Carpe per diem
3,612 posts since Aug 2010
Reputation Points: 563
Solved Threads: 451
Skill Endorsements: 32
Question Answered as of 4 Months Ago by
Reverend Jim
and
adam_k