Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitmap in some cells of a DataGridView column

I have a complete dataGridView with 5 Columns.

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

This is what it should look like:

enter image description here

I've currently tried:

dataGridView1.Rows.Add(   ) ;

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

like image 435
a d Avatar asked Nov 03 '22 15:11

a d


1 Answers

Try this:

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);
like image 75
Nasreddine Avatar answered Nov 11 '22 21:11

Nasreddine