vb.net - 检查 datagridview 中的特定数据类型

标签 vb.net

是否可以检查 datagridview 单元格是否包含特定数据类型。我找不到正确的语法。这就是我想要的。

If DataGridView1.Columns("Name").ValueType = String Then

End If

最佳答案

首先循环遍历 datagridview 中的所有行,然后循环遍历该行中的所有单元格。循环单元格时,检查 Cell.Value 是否为字符串、整数、小数等。

方法如下:

    For Each Row As DataGridViewRow In DataGridView1.Rows
        For Each Cell As DataGridViewCell In Row.Cells
            If TypeOf (Cell.Value) Is String Then
                MsgBox("This cell is a string!")
            End If
        Next
    Next

或者,您可以循环遍历行并通过设置索引立即检查单元格...因此 Row.Cells(0).Value 将采用第一个单元格的值:

    For Each Row As DataGridViewRow In DataGridView1.Rows
        If TypeOf (Row.Cells(0).Value) Is String Then
            MsgBox("String again!")
        End If
    Next

关于vb.net - 检查 datagridview 中的特定数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16546539/

相关文章:

vb.net - 如何抑制 VB 的 "Iteration variable shouldn' t 被用于 lambda 表达式"

xml - 使用 VB.net 或 C# 将具有不同 ElementName 的 xml 序列化为同一对象

vb.net - 'objType' 未定义...实际上,它是,那么为什么会发生这种情况?

asp.net - 将 DropDownList 绑定(bind)到没有数据源的详细信息 View

c# - 如何将 DropDownList 包装在 GridView FooterTemplate 中?

c# - 如何在 vb.net 中实现值类型的 C# 'as' 关键字?

javascript - 回发问题上的html编码

mysql - 我的脚本在重复键上有什么问题?

mysql - 存储过程 VB.NET MYSQL

vb.net - 是否可以为加密/解密程序添加 "Master"密码?