Images in datagridview
#1

i am trying to get images in a column in a datagridview but i cant get it.

 

this is my line to add a row in datagridview:

dataGridView1.Rows.Add("String", (Image)GetEmpty(), - 1, "None", -1);

and this is my GetEmpty() function:

private Bitmap GetEmpty()
{
Bitmap bmp = new Bitmap("Images/Empty.png");
return bmp;
}

but when i run my program and click on an item from a listbox, i get this:

 

2

 

Could anyone help me please?

 

Thanks in advance.

#2

Did you make the column on that datagridview  into "DataGridViewImageColumn": (when you create a column create the column with that type).

Bitmap bmp = new Bitmap("image.bmp");
dataGridView1.Rows.Add("String", (Image)bmp, - 1, "None", -1);

Or you can Change the cell type to "DataGridViewImageCell"

DataGridViewImageCell cell = new DataGridViewImageCell();
cell.Value = (Image )bmp;
dataGridView2.Rows[RowIndex].Cells["MyColumn"] = cell;

#3
thanks someone. i hadnt created the image column correctly.

#4
Topic Closed by a moderator. The reason why: Solved



Forum Jump:


Users browsing this thread: 3 Guest(s)