我最近开始得到这个错误,我不知道为什么。没有什么新的变化,我真的需要一些帮助
If e.Value = "Departure" Then
dgvNotify.Item(0, e.RowIndex).Style.BackColor = Color.LightPink
dgvNotify.Item(1, e.RowIndex).Style.BackColor = Color.LightPink
dgvNotify.Item(2, e.RowIndex).Style.BackColor = Color.LightPink
'dgvNotify.DefaultCellStyle.SelectionBackColor = Color.LightPink
'dgvNotify.DefaultCellStyle.SelectionForeColor = dgvNotify.DefaultCellStyle.ForeColor
Else
dgvNotify.Item(0, e.RowIndex).Style.BackColor = Color.LightGreen
dgvNotify.Item(1, e.RowIndex).Style.BackColor = Color.LightGreen
dgvNotify.Item(2, e.RowIndex).Style.BackColor = Color.LightGreen
'dgvNotify.DefaultCellStyle.SelectionBackColor = Color.LightGreen
'dgvNotify.DefaultCellStyle.SelectionForeColor = dgvNotify.DefaultCellStyle.ForeColor
End If
End If
End Sub
您e. Value
似乎是NULL
,因此您需要改进if
:
If CStr("" & e.Value) = "Departure" Then
dgvNotify.Item(0, e.RowIndex).Style.BackColor = Color.LightPink
dgvNotify.Item(1, e.RowIndex).Style.BackColor = Color.LightPink
dgvNotify.Item(2, e.RowIndex).Style.BackColor = Color.LightPink
'dgvNotify.DefaultCellStyle.SelectionBackColor = Color.LightPink
'dgvNotify.DefaultCellStyle.SelectionForeColor = dgvNotify.DefaultCellStyle.ForeColor
Else
dgvNotify.Item(0, e.RowIndex).Style.BackColor = Color.LightGreen
dgvNotify.Item(1, e.RowIndex).Style.BackColor = Color.LightGreen
dgvNotify.Item(2, e.RowIndex).Style.BackColor = Color.LightGreen
'dgvNotify.DefaultCellStyle.SelectionBackColor = Color.LightGreen
'dgvNotify.DefaultCellStyle.SelectionForeColor = dgvNotify.DefaultCellStyle.ForeColor
End If
CStr(""
CStr("" & DBNull.Value) ' ""
CStr("" & Nothing) ' ""
CStr("" & "Hello World") ' "Hello World"