.net - 告诉 datagridview 忽略 'NULL' 单元格

标签 .net vb.net datagridview null

我有一段代码可以从 datagridview 读取整数和日期值。一些 k 值中有空条目,我试图让应用程序忽略这些单元格,但我没有任何运气。线上弹出错误
j = datediff...

我尝试使用 if 语句来忽略为空的值,但这不起作用。任何帮助将不胜感激。

    For k = 3 To 7 Step 2

        Dim j As Integer

        j = DateDiff(DateInterval.Day, DataGridView1.Rows(e.RowIndex).Cells(k - 2).Value, DataGridView1.Rows(e.RowIndex).Cells(k).Value)

        If DataGridView1.Rows(e.RowIndex).Cells(k + 3).Value = 0 Then

            If j > 7 Then
                DataGridView1.Rows(e.RowIndex).Cells(k + 1).Value = 3
            Else
            End If

        Else
        End If

    Next k

最佳答案

检查单元格值是否为空:

If DataGridView1.Rows(e.RowIndex).Cells(k + 1).Value Is Nothing Then
' your code
End If

关于.net - 告诉 datagridview 忽略 'NULL' 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41059224/

相关文章:

vb.net - 创建 Oracle Connection 导致 COM 类检索出错

c# - 当用户更改单元格值时要捕获的 DataGridView 事件

mysql - 从 DB VB.NET 填充 Datagridview

c# - 当以编程方式更改值时,不触发 DataGridView 中的单元格值更改事件

c# - 如何将方法名称传递给另一个方法并通过委托(delegate)变量调用它?

.net - 在不同的数据库提供者之间同步表

.net - .NET 4.6.1 中的默认 ServicePointManager.SecurityProtocol 值是什么?

.net - 使用 Context.RewritePath 重写到不同的域

c# - 使用所见即所得编辑器编辑 HTML

VB.Net - AssemblyFileVersion & AssemblyFileVersionAttribute 和 AssemblyVersion & AssemblyVersionAttribute 之间有什么区别