Solved

Displaying an Image in a DataGridView Cell

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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