我一直在使用以下代码更改 datagridview 中的单元格值颜色,没有任何问题,直到我将其传输到新项目并将项目连接到不同的服务器。它现在抛出“对象引用未设置为对象的实例”错误。我错过了什么?
它从 GridViewTextBoxColumn1 开始工作,直到它向下移动到 GridViewTextBoxColumn2 并且调试器开始抛出类似的错误。值不能转换为日期时间类型,然后对象引用未设置等。但我到处检查,一切似乎都到位,不明白它是如何以日期时间结束的。
Private Sub TableGrid_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles TableGrid.CellFormatting
For i As Integer = Nothing To Me.TableGrid.Rows.Count - 1
If Me.TableGrid.Rows(i).Cells("GridViewTextBoxColumn1").Value <= 0 Then
Me.TableGrid.Rows(i).Cells("GridViewTextBoxColumn1").Style.ForeColor = Color.Red
End If
Next
For j As Integer = Nothing To Me.TableGrid.Rows.Count - 1
If Me.TableGrid.Rows(j).Cells("GridViewTextBoxColumn2").Value.ToString = "S" Then
Me.TableGrid.Rows(j).Cells("GridViewTextBoxColumn2").Style.ForeColor = Color.Blue
End If
Next
For k As Integer = Nothing To Me.TableGrid.Rows.Count - 1
If Me.TableGrid.Rows(k).Cells("GridViewTextBoxColumn3").Value.ToString = "Z" Then
Me.TableGrid.Rows(k).Cells("GridViewTextBoxColumn3").Style.ForeColor = Color.Blue
End If
Next
End Sub