我想检查datagridview的空单元格为空。因为我使用的是以下代码,但即使单元格已填满,它也会闪烁。检查datagridview的单元格中的空值或空值
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 5 || e.ColumnIndex == 6)
{
if (dataGridView1.CurrentCell.Value == null ||
dataGridView1.CurrentCell.Value == DBNull.Value ||
String.IsNullOrWhiteSpace(dataGridView1.CurrentCell.Value.ToString()))
{
MessageBox.Show("Please enter value");
}
}
}
哪里是错误..
在此先感谢...
习惯上显示消息。但是我看到一个问题,单元格的值不会是'null',它会是'DbNull.Value' – Crowcoder
当你认为它应该为空时,单元格的价值是什么?也许DbNull.Value? –