Hi,
That should help:
' That changes backcolor of Row(1) and Cell(1) to blue
DataGridView1.Rows(1).Cells(1).Style.BackColor = Color.Blue
' That changes forecolor(textcolor of cell) of the same cell to br
DataGridView1.Rows(1).Cells(1).Style.ForeColor = Color.Red
Plus, the code you posted also works OK.
Hope this helps,
Onur Güzel
I am sorry, none of them works for me. The program goes through these
code without any error, but the colors don't display. I am using
Visual Studio 2005 on VISTA Ultimate computer. Should I need to do
some special settings for the DataGridView control?
Thanks!
I just went thru this myself.
You can change the color of a row but not the color of a cell unless you are
in the CellFormatting event of the grid. I changed my code to the
CellFormatting and it worked no problem.
The one change is that you have to do the test for the color in the event
rather than when you might think would be the normal place within your code.
Example:
Private Sub CDListView_CellFormatting(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles
CDListView.CellFormatting
Dim dr As DataGridViewRow = CDListView.Rows(e.RowIndex)
Dim tmp As TmpArtistsCD = CType(dr.DataBoundItem, TmpArtistsCD)
Dim found As Boolean = False
For Each cd As ArtistsCD In q1
If tmp.Album.ToUpper = cd.Album.ToUpper And tmp.Artist = cd.Artist Then
found = True
Exit For
End If
Next
If Not found Then
dr.DefaultCellStyle.BackColor = Color.Tomato
End If
End Sub
Hope this helps
LS