如何验证DataGridView中的空单元格?(VB.net)



我想知道是否有任何正确的方法来验证DataGridView中的空字段。我的意思是,网格内没有空的行。(不仅仅是字段,而是整行(。如果有人知道​​我应该使用的事件或代码将非常有用。提前谢谢。

这就是我要做的:

  1. 使用Rows集合上的强制转换方法(documentation(为IEnumerable(Of DataGridViewRow(
  2. 使用where方法(文档(对集合进行迭代
  3. 在当前迭代行的Cells集合上使用强制转换方法将其转换为IEnumerable(of DataGridViewCell(
  4. 使用all方法(文档(对集合进行迭代
  5. 使用条件语句检查单元格值为零的位置

示例:

Dim emptyRows = DataGridView1.Rows.Cast(Of DataGridViewRow).Where(Function(row) row.Cells.Cast(Of DataGridViewCell).All(Function(cell) cell.Value Is Nothing))
If (emptyRows.Any()) Then
' do something with the empty rows
End If

最新更新