2016-08-08 65 views
0

使用C#和Visual Studio,我有一個DataGridView 2列。對於每一行,第一列將顯示文本。對於除了一個特定行以外的每一行,第二列將顯示文本。在第二列的一個特定單元格中,我需要顯示圖像。如何將圖像添加到DataGridView中的單個特定單元格?

例如:

Row[0].Cell[0] = "test" Row [0].Cell[1] = "test" 
Row[1].Cell[0] = "test" Row [1].Cell[1] = "test" 
Row[2].Cell[0] = "test" Row [2].Cell[1] = need to display an image here 
Row[3].Cell[0] = "test" Row [3].Cell[1] = "test" 

回答

0

不止一種方法去做一件事,但這裏是一個簡單的例子,將設置一個單細胞,顯示的圖像:

Bitmap bmp = (Bitmap) Bitmap.FromFile(someimagefile); 

    DataGridViewImageCell iCell = new DataGridViewImageCell(); 
    iCell.Value = bmp; 
    dataGridView1[1, 2] = iCell; 

當然任何其他圖像源也可以工作。

如果更改它們,請不要泄漏位圖。

相關問題