我正在尝试将图标设置为每个我的数据库值 1,0 的 datagridview 单元格我正在使用此代码(从本网站复制!)
foreach (DataGridViewRow row in DataGridView1.Rows)
{ DataGridViewImageCell cell = row.Cells[8] as DataGridViewImageCell;
if row.Cells[8]==1)
cell.Value = (System.Drawing.Image)Properties.Resources.ok;
if row.Cells[8]==0)
cell.Value = (System.Drawing.Image)Properties.Resources.notOK;
}
但编译器显示此错误:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object.
该代码有什么问题?