Solved

Displaying an Image in a DataGridView Cell

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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

20 Experts available now in Live!

Get 1:1 Help Now