Bitmap in some cells of a DataGridView column

I have a full dataGridView with 5 columns.

Now I want to draw a bitmap in certains cells of these columns.

Here's how it should look:

enter image description here

Currently, I tried:

dataGridView1.Rows.Add(   ) ;

Can you help me draw a bitmap in a new row of dataGridView.Rows?

+5
source share
1 answer

Try the following:

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);
+2
source

All Articles