如果一个单元格是空的,如何忽略

时间:2017-09-10 16:44:25

标签: vb.net

如何使用roscolor()但忽略值(如空单元格)? 如果值大于5,我会着色行但是当单元格中没有任何内容时,我想忽略roscolor()应用,如何?

{{1}}

1 个答案:

答案 0 :(得分:0)

您可以检查空值如下

Public Sub RosColor()
    For i As Integer = 0 To QuoteDataGridView1.Rows.Count() - 1 Step +1
        Dim val = QuoteDataGridView1.Rows(i).Cells(3).Value
        If IsDBNull(val) or val Is Nothing Then
            QuoteDataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.White
        ElseIf CInt(val) < 5 Then
            QuoteDataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red
        ElseIf CInt(val) > 5 And CInt(val) < 10 Then
            QuoteDataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightYellow
        End If