如何使用C#检查datagridview中的空单元格和空单元格 [英] How to check empty and null cells in datagridview using C#
本文介绍了如何使用C#检查datagridview中的空单元格和空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查 datagridview 单元格中的空值和空值...但我做不好...
i am trying to check the datagridview cells for empty and null value... but i can not do it right...
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((String)dataGridView1.Rows[i].Cells[3].Value == String.Empty)
{
MessageBox.Show(" cell is empty");
return;
}
if ((String)dataGridView1.Rows[i].Cells[3].Value == "")
{
MessageBox.Show("cell in empty");
return ;
}
}
我什至试过这个代码
if (String.IsNullOrEmpty(dataGridView1.Rows[i].Cells[3].Value))
{
MessageBox.Show("cell is empty");
return;
}
任何人都可以帮我..这个...
can any one help me.. with this...
推荐答案
我会这样尝试:
foreach (DataGridViewRow rw in this.dataGridView1.Rows)
{
for (int i = 0; i < rw.Cells.Count; i++)
{
if (rw.Cells[i].Value == null || rw.Cells[i].Value == DBNull.Value || String.IsNullOrWhiteSpace(rw.Cells[i].Value.ToString())
{
// here is your message box...
}
}
}
这篇关于如何使用C#检查datagridview中的空单元格和空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文