' Changes the foreground color of cells in the "Ratings" column
' depending on the number of stars.
Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As DataGridViewCellFormattingEventArgs) _
Handles dataGridView1.CellFormatting
If e.ColumnIndex = dataGridView1.Columns("Rating").Index _
AndAlso e.Value IsNot Nothing Then
Select Case e.Value.ToString().Length
Case 1
e.CellStyle.SelectionForeColor = Color.Red
e.CellStyle.ForeColor = Color.Red
Case 2
e.CellStyle.SelectionForeColor = Color.Yellow
e.CellStyle.ForeColor = Color.Yellow
Case 3
e.CellStyle.SelectionForeColor = Color.Green
e.CellStyle.ForeColor = Color.Green
Case 4
e.CellStyle.SelectionForeColor = Color.Blue
e.CellStyle.ForeColor = Color.Blue
End Select
End If
End Sub