Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

how to add an image(.gif) to a datatable cell.

my datatable column is

      dt5.Columns.Add(new DataColumn("Availability", typeof(Byte[])));

i am performing the following check
if(available==false)
                        {
                              img1.ImageUrl="";
                              img1.ImageUrl="green.gif";
                              DRC[j][1]=img1;

// i am gettin error in the above line.(i.e DRC[j][1]=img1)

                        }
0
poogie22
Asked:
poogie22
1 Solution
 
peterdunganCommented:
You probably need to store a string in DRC[j][1] rather than an image object.
0
 
CollindsouzaCommented:
or you can do it the following way...

here is an example

            //init
            dataGridView1.AutoGenerateColumns = false;
            DataTable dt = new DataTable();
            Bitmap bmp = new Bitmap("test.bmp");            

            //bitmap to byte[] and to datatable
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] buf = ms.ToArray();
           
            //bind            
            dt.Columns.Add("Pic", typeof(Byte[]));
            dt.Rows.Add(buf);
            DataGridViewImageColumn cl = new DataGridViewImageColumn();
            cl.DataPropertyName = "Pic";
            dataGridView1.Columns.Add(cl);
            dataGridView1.DataSource = dt;
0
 
prajapati84Commented:
Try this one, Some improvement to Collindsouza's code...

dt5.Columns.Add(new DataColumn("Availability", typeof(Byte[])));

if(available==false)
{
     img1.ImageUrl="green.gif";
     Bitmap bmp = new Bitmap("green.gif");
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     Picture_Employee.Image.Save(ms, Picture_Employee.Image.RawFormat);
     byte[] arrImage = ms.GetBuffer;
     ms.Close();
     DRC[j][1]=arrImage;
}

Regards,
Mukesh
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now