Change color of DataGridView row (BackColor)

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
 
L

Lloyd Sheen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top