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

前端 未结 8 2471
太阳男子
太阳男子 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:52

    I think you should use this:

    for (int i = 0; i < dataGridView1.RowCount; i++)
    {
        for (int j = 0; j < dataGridView1.ColumnCount; j++) 
        {
            if (dataGridView1.Rows[i].Cells[j].Value == DBNull.Value)
            {
                dataGridView1.Rows[i].Cells[j].Value = "null";
            }
        }
    }
    dataGridView1.Update();
    

提交回复
热议问题