Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-27
3
Medium Priority
?
366 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

715 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