我想知道是否有任何正确的方法来验证DataGridView中的空字段。我的意思是,网格内没有空的行。(不仅仅是字段,而是整行(。如果有人知道我应该使用的事件或代码将非常有用。提前谢谢。
这就是我要做的:
- 使用Rows集合上的强制转换方法(documentation(为IEnumerable(Of DataGridViewRow(
- 使用where方法(文档(对集合进行迭代
- 在当前迭代行的Cells集合上使用强制转换方法将其转换为IEnumerable(of DataGridViewCell(
- 使用all方法(文档(对集合进行迭代
- 使用条件语句检查单元格值为零的位置
示例:
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