Rekcs Rekcs - 1 year ago 68 Question

Color empty space on DataGridView

I am trying to created a method where I can color the empty/null space on the datagridview. It is possible to do that? I was digging on that content but what I've found didn't solved my problem.

You know any method to solve this?

Answer Source

You can use this methode to that :

Sub SetColorEmptyCellGrid(grid As DataGridView, myColor As Color)
    For Each row As DataGridViewRow In grid.Rows
        For i As Integer = 0 To row.Cells.Count - 1
            If row.Cells(i).Value Is Nothing OrElse row.Cells(i).Value Is DBNull.Value OrElse String.IsNullOrWhiteSpace(row.Cells(i).Value.ToString()) Then
                row.Cells(i).Style.BackColor = Color.Blue
            End If
End Sub

and you call method for example with :

SetColorEmptyCellGrid(DataGridViewName, Color.Red)