如果行/列单元格为空,则突出显示datagridview行(vb.net)

时间:2015-01-28 12:33:47

标签: vb.net

我有一个datagridview,如果单元格中没有值,则会突出显示自己,此时它只适用于一个单元格,我想再添加2个单元格,所以如果3个单元格中没有值,则突出显示行。 / p>

目前的代码:

Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting

    For i As Integer = 1 To Me.DataGridView1.Rows.Count - 1
        If Me.DataGridView1.Rows(i).Cells("DateFixed1").Value = ("") Then
            Me.DataGridView1.Rows(i).Cells("DateFixed1").Style.ForeColor = Color.Black
            Me.DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.PaleVioletRed
        End If
    Next

End Sub

1 个答案:

答案 0 :(得分:0)

For Each row As GridViewRow In Me.DataGridView1.Rows
        For Each cell As DataGridViewCell In row.cells
            If cell.Value = ("") 
            Then
               cell.Style.ForeColor = Color.Black
               row.DefaultCellStyle.BackColor = Color.PaleVioletRed
            End If
        Next
Next