LCKB
Images in datagridview - Printable Version

+- LCKB (https://lckb.dev/forum)
+-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109)
+--- Forum: Programmers Gateway (https://lckb.dev/forum/forumdisplay.php?fid=196)
+---- Forum: Coders Talk (https://lckb.dev/forum/forumdisplay.php?fid=192)
+---- Thread: Images in datagridview (/showthread.php?tid=2306)



- soryjero - 08-16-2013


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.




- someone - 08-16-2013


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;




- soryjero - 08-16-2013

thanks someone. i hadnt created the image column correctly.




- Johnny5 - 08-17-2013

Topic Closed by a moderator. The reason why: Solved