我试图更改单元格的图像,但我一直收到一条错误消息,指出它无法转换为布尔值?
以下是我的代码并不完全确定我在这里做错了什么。它说boolean所以我认为这是if语句的问题,因为它会检查它是否为真。
但是没关系:我发了一条调试消息,它运行得很好。问题是尝试将特定单元格的值设置为图像。
Image heartbeat = Image.FromFile(Directory.GetCurrentDirectory() + "\\alive.ico");
DataGridViewImageColumn alive = new DataGridViewImageColumn();
DataTable stores = new DataTable();
SQLiteConnection m_dbConnection;
m_dbConnection = new SQLiteConnection("DataSource=db.sqlite;Version=3;");
SQLiteDataAdapter adapter = new SQLiteDataAdapter("select NO, NO2, CODE, IP_ADDRESS from lite", m_dbConnection);
adapter.Fill(stores);
dataGridView1.DataSource = stores;
dataGridView1.Columns.Add(alive);
alive.Image = image;
dataGridView1.Columns[alive.Name].DisplayIndex = 1;
foreach(DataGridViewRow rrow in dataGridView1.Rows)
{
if(rrow.Cells["IP_ADDRESS"].Value.ToString() == "")
{
rrow.Cells[alive.Name].Value = heartbeat;
}
else
{
//alive.Image = heartbeat;
}
}
错误讯息:
System.FormatException:Value 'System.Drawing.Bitmap' cannot be converted to type Boolean'
答案 0 :(得分:0)
解决了它...我设置了alive.Image = null然后一切正常。
谢谢,