Results 1 to 7 of 7

Thread: How to show images in DataGridView?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2012
    Posts
    53

    How to show images in DataGridView?

    Attachment 99251

    Code:
    Dim sqlcmd As String = "StoredProcedure"
    Dim conn As New SqlConnection("ConnectionString")
    Dim find As New SqlCommand(sqlcmd, conn)
    find.CommandType = CommandType.StoredProcedure
    find.Parameters.Add("@id", SqlDbType.Int).Value = txtid.Text
    Dim da As New SqlDataAdapter(find)
    Dim ds As New DataSet
      Try
        conn.Open()
        da.Fill(ds)
        conn.Close()
        DataGridView1.DataSource = ds.Tables(0)
        DataGridView1.Columns(0).HeaderText = "Name"
        DataGridView1.Columns(1).HeaderText = "Status"
      Catch ex As Exception
        MsgBox("Error: " & Ex.Message, MsgBoxStyle.Information, "ERROR!")
      End Try
    Hello,
    This example "Status" is "Bit" (True/False) and program shown in Checkbox but i wanna show only image.
    Eg: True.bmp or False.gif
    Thanks.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to show images in DataGridView?

    Interesting. So bitmaps are True and gifs are False? You'll be wanting a DataGridViewImageColumn then.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2012
    Posts
    53

    Re: How to show images in DataGridView?

    "Status" column is changeable value..
    How to show True.png or False.png with value?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to show images in DataGridView?

    You don't. Well you don't directly. You have to add the image column, hide the status column but use its values to determine which pictures to load. You can only do that the good old fashioned loop method post binding.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2012
    Posts
    53

    Re: How to show images in DataGridView?

    Sorry my English a little.
    imageColumn is not support fill method?
    Only using while method for image show in dataGridView?

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: How to show images in DataGridView?

    The following VS2010 shows how to display images based on the value of a column other than the image column. Images are icon files in the project resource file. By taking your time to study the code and understand the code you should have no problem adapting what is shown to use other image types i.e. jpeg, bmp etc.

    VS2010 project on SkyDrive, VB.NET Option Strict On.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2012
    Posts
    53

    Re: How to show images in DataGridView?

    @kevininstructor,
    Thanks for example but this code is very long and professional. I am new to VB.NET and using tiny codes.
    My problem only change checkbox to image in column.
    Thank you for help.

    Code:
    if a=True then 
    a.Value = Image.FromFile("C:\Pictures\True.ico")
    else
    a.Value = Image.FromFile("C:\Pictures\False.ico")
    end if

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width