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 ;

   1: dataGridView1.DataSource = siparis_tablo_guncel;

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;

   1: DataGridViewImageColumn img = new DataGridViewImageColumn();

   2:  

   3: img.Name = "img";

   4: img.HeaderText = "Image Column";

   5: img.ValuesAreIcons = true;

   6:  

   7: dataGridView1.Columns.Add(img);

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;

   1: int number_of_rows = dataGridView1.RowCount;

   2: for (int i = 0; i < number_of_rows; i++)

   3: {

   4:     if (dataGridView1.Rows[i].Cells[6].Value.ToString() == "true")

   5:     {

   6:         Icon image = SUT.Properties.Resources.succcess_icon;

   7:         dataGridView1.Rows[i].Cells["img"].Value = image;

   8:     }

   9:     else

  10:     {

  11:         Icon image = SUT.Properties.Resources.cancel_icon;

  12:         dataGridView1.Rows[i].Cells["img"].Value = image;

  13:     }

  14: }

 

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

Have fun!

Fork me on GitHub

Being the master of a IBM x3200

Been a long time since I posted anything. There was a reason for that you see I was looking for a job. And guess what I found one! And guess what more! I am now the sole master of a IBM x3200 server!!IBM x3200 server This is me and the server. I must admit I have never set up a server from nothing before. So far servers were given to me already set up. All I had to do was to add and remove software. Now I have to set up the whole network AND write the software. Not complaining! I am just thrilled! Going to be attending summer school too. So will be busy busy busy. And you know what busy busy busy means. ( Hint: Less posts)

Oh yeah talking of posts. According to my site statistics I am getting around a thousand or so clicks a week. My question is why are spams the only ones sending me comments? Please leave comments!!

Why Apple will lose the bet on iPAD

SAN FRANCISCO - JANUARY 27:  Apple Inc. CEO St...
Image by Getty Images via Daylife

Apple made a new product called iPad. Like their iPod and other iPod related items they expect the consumers to consume this product. However it seems iPad has done couple things wrong and is soon going to meet up with a wall. The walls name is Google Chrome OS tablets.

iPad does not have any USB ports hence the only portability you will be getting is from the other connections like Wi-Fi, 3G, Bluetooth and SIM card tray… But you won’t get your USB. Now some will argue why you would need a USB input here are a few examples; 1. USB keyboard 2.USB mouse 3.USB data stick 4.USB external harddrive 5.USB video cam etc etc etc…. As you can see USB would have added many more functionalities to a simple over sized iPhone.

Another point why users won’t (and/or isn’t) dying to get an iPad is it’s marvelous screen. While many iCandy users will enjoy reading their long 365 page pdf’s on, a 9.7-inch (diagonal) LED-backlit glossy widescreen, Multi-Touch display with IPS technology 1024-by-768-pixel resolution at 132 pixels per inch (ppi) Fingerprint-resistant oleophobic coating 9.7-inch (diagonal) LED-backlit glossy widescreen Multi-Touch display with IPS technology1024-by-768-pixel resolution at 132 pixels per inch (ppi) and its fingerprint-resistant oleophobic coating display… while some other people would rather read their pdf’s on a simple Kindle or another generic e-ink display… You see most power users (a big market that bought the iPod and the iPhone) already have a tablet. And a e-reader. Why should they bother to pay more for less?

And of course there is the wall where iPad will soon be colliding. Whether this train of Apple iEmpire will pass through it like a it was a hay stack or stops for good depends on GoogleChromeTablet pc.

Google has be feverishly working on a new operating system called Google Chrome OS they say that the first computers to use the Google Chrome Os will be the net-books. These light portables are ideal for Google Chrome OS since basically it works on this idea; everything will work in the “internet-cloud”.

Google has also has also announced that this OS will also work in PC‘s and there goes a punch to both Microsoft AND Apple. Google is entering the OS market. And it is making big promises which developers and users around the world hope they will keep.

Google has already started posting design examples on their web site. One of them is this short video I stole from them.

Get the Flash Player to see this content.

I hope you enjoyed this post… Won’t get iPad even if it was free… Sorry…