[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Displaying an Image in a DataGridView Cell

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
alfardan
Asked:
alfardan
1 Solution
 
RimvisCommented:
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
 
alfardanAuthor Commented:
Perfect, got it working now... thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now