2012-09-28 41 views
5

我有一個包含5列的完整的dataGridView。DataGridView列的某些單元格中的位圖

現在,我想在這些列的某些單元格中繪製位圖。

這是它應該是什麼樣子:

enter image description here

目前我已經試過:

dataGridView1.Rows.Add( ) ; 

你能幫我畫在dataGridView.Rows的新行的位圖?

+1

這是WPF或WinForms的? – Candide

+0

winform和c#。 –

+0

位圖來自哪裏?你想如何在'DataGridView'中繪製?這行代碼本身不會做任何與位圖相關的任何事情,它只會添加一個新行。你能詳細說明你想要完成什麼,DataGridView目前看起來像什麼以及你希望如何修改它? – David

回答

2

試試這個:

dataGridView1.Columns.Add("columnName1", "Column 1 Header"); 
dataGridView1.Columns.Add("columnName2", "Column 2 Header"); 

var row1 = new DataGridViewRow(); 
row1.Cells.Add(new DataGridViewImageCell { Value = new Bitmap(@"C:\Path\to\image.jpg") }); 
row1.Cells.Add(new DataGridViewTextBoxCell { Value = "string" }); 
dataGridView1.Rows.Add(row1); 

var row2 = new DataGridViewRow(); 
row2.Cells.Add(new DataGridViewTextBoxCell { Value = "string"}); 
row2.Cells.Add(new DataGridViewImageCell { Value = new Bitmap(@"C:\Path\to\image.jpg") }); 
dataGridView1.Rows.Add(row2); 
+0

Wow.thank很多。 –

+0

@MehdiKhademloo不客氣。 [請記住標記可幫助解決問題的答案](http://meta.stackexchange.com/a/5235/171237)。 – Nasreddine

相關問題