Check if datagridview cell is null or empty
This question already has an answer here:
我会遍历使用类似下面的东西的单元格..
foreach (DataGridViewRow dgRow in dataGridView1.Rows)
{
var cell = dgRow.Cells[7];
if (cell.Value != null) //Check for null reference
{
cell.Style.BackColor = string.IsNullOrEmpty(cell.Value.ToString()) ?
Color.LightCyan :
Color.Orange;
}
}
You don't need ToString()
. See here.
The below code is enough.
string conte = dataGridView1.Rows[rowIndex].Cells[7].Value;
Also you may try something like:
if (string.IsNullOrEmpty(dataGridView1.Rows[0].Cells[7].Value as string))
链接地址: http://www.djcxy.com/p/28048.html