是否可以检查 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/