How to add images to DataGridView cell using C# and Windows Forms

There are many ways to skin this old cat. When choosing the way, you must first decide when should the adding of images take place. I chose to add images during sorting.

Let us assume you already added some data to gridview via datatable using ;

So now you know we have a filled up dataGridView.

Now let us assume in the dataGridView1 we want to add images according to the data within the 6th column. So what we first need to do is to create an image column by writing;

Now we have a image column. With the name “img” with the header “Image Column” As you can see in the 5th line I have stated that my images are actually icons. The reason I did this was that I found out that icons take up less space and flickers less. You can if you want change this option as you see fit.

Now let us get cracking and add those images according to the columns;

 

I hope this has been informative. Please do tell if you see any mistakes and wish to make suggestions.

Have fun!

18 thoughts on “How to add images to DataGridView cell using C# and Windows Forms

    1. John Roach Post author

      Oh that is the namespace of the program in Turkish it is a acronym for SÜT : Sipariş Ürün Teslim which means in English OPD: Order Product Delivery.
      I used this part of the code in another program. Forgot to rename it.

      Reply
    1. John Roach Post author

      I think you are talking of :
      6: Icon image = SUT.Properties.Resources.succcess_icon;
      7: dataGridView1.Rows[i].Cells[“img”].Value = image;

      The 6th line sets the icon “image” to the succcess_icon image from the resources. (SUT is the namespace in which I added the resource) The 7th line adds the icon “image” to the “img” cell.

      11 does the same thing.

      Reply
  1. http://google.com

    This specific article, “How to add images to
    DataGridView cell using C# and Windows Forms | John Roach” was in
    fact very good. I am making out a backup to
    demonstrate to my personal close friends. Thanks-Danuta

    Reply

Leave a Reply