Solved

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

Posted on 2006-11-27
3
363 Views
Last Modified: 2012-08-13
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
Comment
Question by:poogie22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:peterdungan
ID: 18018048
You probably need to store a string in DRC[j][1] rather than an image object.
0
 
LVL 5

Accepted Solution

by:
Collindsouza earned 500 total points
ID: 18018081
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
 
LVL 5

Expert Comment

by:prajapati84
ID: 18026819
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question