Skip to content

How to show images in datagirdview form imagefolder?

Rashid Khan

Asked Oct 9, 2013, 3:37 AM EDT1 answer
Share
LinkedInX
I m trying to bind datagridview from images which are stores in imagefolder dynamically.

i have try this

C#
 System.IO.DirectoryInfo inputDir = new System.IO.DirectoryInfo("ImageFolder Path which are in my application");
            try
            {
                if ((inputDir.Exists))
                {

                    System.IO.FileInfo file = null;


                    foreach (System.IO.FileInfo eachfile in inputDir.GetFiles())
                    {
                        file = eachfile;
                        if (file.Extension.ToLower() == ".jpg")
                        {




                            DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
                            imageColumn.Name = "ImageColumn";
                            imageColumn.HeaderText = "An Image!";
                            var imagepath = file.FullName;
                           Image image = System.Drawing.Image.FromFile(file.FullName);
                            imageColumn.Image = image;
                            dataGridView1.Columns.Insert(0, imageColumn);

                        }
                        i++;
                    }
                            

on designer side. I places datagridview (empty).
in out put only columns header show . not a single image load.

please tell me how to show images in datagridview.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Use This Code



    SQL
    Bitmap img;  img = new Bitmap(@"c:\images\mousepad.jpg");  // Create the DGV with an Image column  DataGridView dgv = new DataGridView();  this.Controls.Add(dgv);  DataGridViewImageColumn imageCol = new DataGridViewImageColumn();  dgv.Columns.Add(imageCol);  // Add a row and set its value to the image  dgv.Rows.Add();  dgv.Rows[0].Cells[0].Value = img;
    0