我試圖設置圖標,按我的分貝vaules是1,0 我是用這個代碼的datagridview細胞(從該網站複製!)設置圖標,每分貝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.
該代碼有什麼問題?
指定圖像和檢查單元格的值相同? – Sathish
4例如,我想爲1值設置綠色刻度圖標和0值的紅色停止圖標,如何在datagridview中綁定數據後或從dataTable中的數據庫中獲取數據後,如何通過代碼執行此操作? tanx –
你試過我的回答 – Sathish