How to check empty and null cells in datagridview using C#

前端 未结 8 2477
太阳男子
太阳男子 2020-12-17 15:02

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++)
{
         


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 15:48

    I would try like 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...
        }
      } 
    }
    

提交回复
热议问题