2012-04-27 79 views
0

一直玩我的程序的用戶界面,並有一個小功能,與同一行上的單元格進行比較,併爲該單元格指定顏色。 我現在真正想要的是簡單地向該單元格添加圖像向上或向下箭頭。不幸的是,似乎沒有我覺得難以置信的劃線員。C#將圖像動態添加到單元格

這裏是我當前的代碼:

DataGridViewImageCell p1 = new DataGridViewImageCell(); 

ParetoGrid.Columns.Add(new DataGridViewColumn() { CellTemplate = p1, FillWeight = 1, HeaderText = "p1", Name = "p1", Width = 30}); 




private void ShowArrow() 
    { 
     foreach (DataGridViewRow paretoRow in ParetoGrid.Rows) 
     { 
      if ((paretoRow.Cells["Pareto6"].Value != null) && (Convert.ToInt32(paretoRow.Cells["CurrentPareto"].Value) < (Convert.ToInt32(paretoRow.Cells["NewPareto"].Value)))) 
      { 
       paretoRow.Cells["p1"].Value = //image?; 
      } 
      else if ((paretoRow.Cells["Pareto6"].Value != null) && (Convert.ToInt32(paretoRow.Cells["CurrentPareto"].Value) > (Convert.ToInt32(paretoRow.Cells["NewPareto"].Value)))) 
      { 
       ParetoGrid.Rows[paretoRow.Index].DefaultCellStyle.BackColor = Color.LightGreen; 
      } 


     } 
    } 

林希望有人知道,有一個襯墊。哦,我想添加圖像的列也是DataGridViewImageCell。

非常感謝!

到目前爲止,我只需要創建一個新的圖像,然後

paretoRow.Cells["p1"].Value = theImage; 

問題我得到的是錯誤:格式化單元有錯誤的類型!

回答

0

您應該使用DataGridTemplateColumn包含圖像控件。一般專欄不支持顯示圖像。

+0

你可以說出你的意思嗎?你在談論分配圖像還是你在談論之前? – lemunk 2012-04-27 09:11:08

+0

還是你的意思是用這個替換DataGridViewImageCell? – lemunk 2012-04-27 09:12:28

+0

我忘記了該列還需要是圖像類型,該問題已解決 – lemunk 2012-04-27 09:31:43

相關問題