locked
Database Images to DatagridView RRS feed

  • Question

  • Hi, I am trying to display a list of images from a database to a datagridview. I am wanting to set the size of the image and have the user scroll through the images for evaluations.   For some reason, I get one image and nothing after that, except for a X icon in the following rows.

    This is what my test code is looking like.  the datatable dtRSTImages contains one column with about 60 rows, Each row has valid images.

      Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
    
            With dgvimages
                Dim imagecol As DataGridViewImageColumn = New DataGridViewImageColumn
                With imagecol
                    .ImageLayout = DataGridViewImageCellLayout.Zoom
                End With
                .Columns.Add(imagecol)
            End With
    
            For Each row As DataRow In dtRSTImages.Rows
                dgvimages.Rows.Add()
                dgvimages.Rows(0).Cells(0).Value = row.Item(0)
            Next
    
        End Sub

    Any help on why all the images are not show up?   If I do query with all the fields the images also show up, but I just want to see the images and resize the column width and row Height to make it easy to see the images.  

    Also, while I am asking....  would this be the best way to show a set of images?

    Wednesday, June 29, 2016 1:37 PM

Answers

  • Saving to SQl 2008 r2, saving as binary content.  The problem is not being able to read the data or display the images in a picturebox... or when I select all the data to a datagrid, the issue becomes when I try to just select the image as the only column in a datagridview control. 

    I've not had a change yet to look over Cor's suggestion.


    Have you looked at mine? It's MS-Access but the methods are the same for either database.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by LandLord324 Tuesday, July 5, 2016 5:11 PM
    Saturday, July 2, 2016 2:56 PM

All replies

  • look at the tip for this on our website.

    http://www.vb-tips.com/TextAndImageColumn.aspx


    Success
    Cor

    Wednesday, June 29, 2016 1:47 PM
  • Here is a sample using MS-Access.

    https://code.msdn.microsoft.com/Reading-and-writing-to-MS-945a0615


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, June 29, 2016 3:49 PM
  • Probably would help to identify the type of database you are working with and how the image was saved.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, June 29, 2016 4:34 PM
  • Saving to SQl 2008 r2, saving as binary content.  The problem is not being able to read the data or display the images in a picturebox... or when I select all the data to a datagrid, the issue becomes when I try to just select the image as the only column in a datagridview control. 

    I've not had a change yet to look over Cor's suggestion.


    • Edited by LandLord324 Wednesday, June 29, 2016 5:38 PM
    Wednesday, June 29, 2016 5:36 PM
  • Thanks Karen, however I am able to read and write images to the database just fine, for the most part :)
    Wednesday, June 29, 2016 5:39 PM
  • Saving to SQl 2008 r2, saving as binary content.  The problem is not being able to read the data or display the images in a picturebox... or when I select all the data to a datagrid, the issue becomes when I try to just select the image as the only column in a datagridview control. 

    I've not had a change yet to look over Cor's suggestion.


    Have you looked at mine? It's MS-Access but the methods are the same for either database.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by LandLord324 Tuesday, July 5, 2016 5:11 PM
    Saturday, July 2, 2016 2:56 PM
  • Thanks Karen, that is what I am looking for, nice samples.  I cannot get my images to resize to the cell.

    this was the simple way I did it.. shows 3 columns.. FileName, Remarks, FileContrents(pictures)

            Dim x As clsSQL = New clsSQL
            Dim dv As DataView = New DataView
    
            dgvData.DataSource = x.QueryData_DataReader(strQuery_Data)
            dtRSTImages = x.QueryData_DataReader(strQuery_Images)
            dgvimages.AutoGenerateColumns = True
    
            dgvimages.DataSource = dtRSTImages
    
    How can I get my images to resize.   I am guessing my next option would be to put 3 or 4 pictureboxes on the form and write code when the user scrolls through records.
    Tuesday, July 5, 2016 2:48 PM
  • Not sure if this is exactly what you are looking for, but try setting the picture column ImageLayout property to Stretch in the DataGridView. There may be some auto size properties to modify as well depending upon exactly what behavior you would like to see.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, July 5, 2016 3:39 PM
  • Exactly, use PictureBox.DataBinding.Add then when moving rows the proper image will show.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 5, 2016 3:45 PM