Change color of DataGridView row (BackColor)

  • Thread starter Thread starter Lloyd Sheen
  • Start date Start date
L

Lloyd Sheen

I am trying to change the color of certain rows of a DataGridView based on
criteria.

I have tried about every combination but still no joy.

Private Sub ShowTrueColors()
Dim notfound As New DataGridViewCellStyle
notfound.BackColor = Color.Tomato
Dim badReleaseYear As New DataGridViewCellStyle
badReleaseYear.BackColor = Color.Coral
For Each dr As DataGridViewRow In PossibleCDListView.Rows
Dim tmp As ArtistsCD = CType(dr.DataBoundItem, ArtistsCD)
Dim found As Boolean = False
For Each cd As TmpArtistsCD In q2
If tmp.Album = cd.Album And tmp.Artist = cd.Artist Then
found = True
Exit For
End If
Next
If Not found Then

dr.DefaultCellStyle.BackColor = Color.Tomato
End If
Next
PossibleCDListView.Refresh()
End Sub


I know the line
dr.DefaultCellStyle.BackColor = Color.Tomato

is being executed but there is no change in the color.

Why is everything to do with Grid so hard for MS to get right or easy??

LS
 
Lloyd Sheen said:
I am trying to change the color of certain rows of a DataGridView based on
criteria.

I have tried about every combination but still no joy.

Private Sub ShowTrueColors()
Dim notfound As New DataGridViewCellStyle
notfound.BackColor = Color.Tomato
Dim badReleaseYear As New DataGridViewCellStyle
badReleaseYear.BackColor = Color.Coral
For Each dr As DataGridViewRow In PossibleCDListView.Rows
Dim tmp As ArtistsCD = CType(dr.DataBoundItem, ArtistsCD)
Dim found As Boolean = False
For Each cd As TmpArtistsCD In q2
If tmp.Album = cd.Album And tmp.Artist = cd.Artist Then
found = True
Exit For
End If
Next
If Not found Then

dr.DefaultCellStyle.BackColor = Color.Tomato
End If
Next
PossibleCDListView.Refresh()
End Sub


I know the line
dr.DefaultCellStyle.BackColor = Color.Tomato

is being executed but there is no change in the color.

Why is everything to do with Grid so hard for MS to get right or easy??

LS

I found the answer. So some reason you have to handle this in the
CellFormatting event.

Once again I ask WHY??

LS
 
Back
Top