Solved

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

Posted on 2006-11-27
3
358 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
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now