我正在检查所选行的单元格7,8,9是否为null。但是,即使所有单元格的值都为空,它也只显示“已启用”。这里是我的代码如何检查Datagridview中选定行的特定列是否为空?
private void btnTest_Click_1(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dgvReceivingproducts.Rows)
{
if (row.Cells[7].Value != null && row.Cells[8].Value != null && row.Cells[9].Value != null)
{
lblchecker.Text = "enabled";
}
else
{
lblchecker.Text = "disabled";
}
}
}
作为@PabloJ建议在他的回答,请核对'DbNull.Value'取代'null' – Pikoh