Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to image show or display in datagridview existing column in c# .net windows application?

I want to display images in these column.
How it can be possible.

FloorTexture1|FloorTexture2|FloorTexture3|FloorTexture4|FloorTexture5|FloorTexture6
System.Drawing.Bitmap|Library\asd.png|Library\aaa.png|Library\sss.png|Library\eee.png|Library\qqq.png

and all datatypes are varchar(max).

I want to display only image in these column.

I am writing this code for display image but it's not displaying.

C#
 foreach (DataGridViewRow row1 in dgvDisplayTiles.Rows)
                {
                    string imgPath = System.IO.Path.Combine(Application.StartupPath + row1.Cells[3].Value.ToString());
                    if (imgPath!=null)
                    {
                        row1.Cells[3].Value = (Bitmap)System.Drawing.Image.FromFile(imgPath, true);
                    }
                    else
                    {
                        MessageBox.Show("Invalid Path");
                    }
                }

But only display "System.Drawing.Bitmap" in datagrdiview image column.
Please help me, It's urgent.
Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Updated 2-Dec-13 23:57pm
v7
Comments
AnthonyMG 29-Nov-13 7:31am    
Try setting the image from dataGridView Cellformatting event.

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "ImageColumn")
{
e.Value = Image.FromFile(@"C:\Pictures\TestImage.jpg");
}
}
Member 10279627 3-Apr-14 8:16am    
o ho ho

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900