Solved

Displaying an Image in a DataGridView Cell

Posted on 2012-04-03
2
284 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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