Solved

Displaying an Image in a DataGridView Cell

Posted on 2012-04-03
2
285 Views
Last Modified: 2012-04-04
Hi

How can I add an image to a datagridview cell (rows section, not header)? I tried the following code but I got the attached datagridview which is now what I want:

            Dim img_down As New DataGridViewImageCell()
            Dim inImg As Image = Image.FromFile(IO.Directory.GetCurrentDirectory() + "\AppImages\down_arrow.jpg")
            img_down.Value = inImg

            AppListOrderGridView.Columns.Add("MoveDown", "")
            AppListOrderGridView.Columns.Add("Value", "")
            AppListOrderGridView.Columns.Add("ApplNum", "No.")
            AppListOrderGridView.Columns.Add("Priority", "Priority")
            AppListOrderGridView.Columns.Add("ApplName", "Application Name")


            For i = 0 To ApplicationList.Tables(0).Rows.Count - 1
                AppListOrderGridView.Rows.Add(img_down, "Up", (i + 1), "P", ApplicationList.Tables(0).Rows(i).Item("Appname"))
            Next

Open in new window

grid.png
0
Comment
Question by:alfardan
2 Comments
 
LVL 19

Accepted Solution

by:
Rimvis earned 500 total points
ID: 37804795
Hello alfardan,

You should use DataGridViewImageColumn, not DataGridViewImageCell.

Try this:
        Dim img_down As New DataGridViewImageColumn()
        Dim inImg As Image = Image.FromFile(IO.Directory.GetCurrentDirectory() + "\AppImages\down_arrow.jpg")
        img_down.Name = "MoveDown"
        img_down.HeaderText = ""
        img_down.Image = inImg

        AppListOrderGridView.Columns.Add(img_down)
        AppListOrderGridView.Columns.Add("Value", "")
        AppListOrderGridView.Columns.Add("ApplNum", "No.")
        AppListOrderGridView.Columns.Add("Priority", "Priority")
        AppListOrderGridView.Columns.Add("ApplName", "Application Name")


        For i = 0 To ApplicationList.Tables(0).Rows.Count - 1
            AppListOrderGridView.Rows.Add(inImg, "Up", (i + 1), "P", ApplicationList.Tables(0).Rows(i).Item("Appname"))
        Next

Open in new window

0
 

Author Closing Comment

by:alfardan
ID: 37805263
Perfect, got it working now... thank you
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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