Vin*_*ent 13 c# datagridview winforms
我试图检查datagridview单元格的空值和空值...但我不能正确...
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 ;
}
}
Run Code Online (Sandbox Code Playgroud)
我甚至试过这个代码
if (String.IsNullOrEmpty(dataGridView1.Rows[i].Cells[3].Value))
{
MessageBox.Show("cell is empty");
return;
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个...
Dav*_*ras 17
我会尝试这样的:
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...
}
}
}
Run Code Online (Sandbox Code Playgroud)
if (String.IsNullOrEmpty(dataGridView1.Rows[i].Cells[3].Value as String))
{
MessageBox.Show("cell is empty");
return;
}
Run Code Online (Sandbox Code Playgroud)
添加as String,它对我有用。