2012-09-28 36 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

相关问题