Results 1 to 10 of 10

Thread: Display Image From dataGridView to multi picturebox in VB.NET

Threaded View

  1. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: Display Image From dataGridView to multi picturebox in VB.NET

    Quote Originally Posted by jmcilhinney View Post
    You should bind the DataTable to the DataGridView via a BindingSource. You can then handle the CurrentChanged event of that BindingSource and get the current record from the Current property. You can then build all the file paths and set them in the appropriate PictureBoxes:
    vb.net Code:
    1. Private Sub BindingSource1_CurrentChanged(...) Handles BindingSource1.CurrentChanged
    2.     Dim currentRow = DirectCast(BindingSource1, DataRowView)
    3.     Dim folderPath = CStr(currentRow("PATH"))
    4.  
    5.     PictureBox1.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME1")))
    6.     PictureBox2.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME2")))
    7.     PictureBox3.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME3")))
    8.     PictureBox4.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME4")))
    9.     PictureBox5.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME5")))
    10.     PictureBox6.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME6")))
    11. End Sub
    Dear Mr. jmcilhinney
    Thanks for your reply. Previously I used databindings with only a filename benchmark in datagridview it makes it very slow because the data record was fifty thousand. code from you whether you can appear the image just by clicking in the "ITC" field only. From your code there is an error as follows
    Code:
    Private Sub BindingSource1_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingSource1.CurrentChanged
            Dim currentRow = DirectCast(BindingSource1, DataRowView) 'Error Value of type 'System.Windows.Forms.BindingSource' cannot be converted to 'System.Data.DataRowView'
            Dim folderPath = CStr(currentRow("PATH"))
    
            PictureBox1.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME1"))) 'Error Combine' is not a member of 'String'
            PictureBox2.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME2"))) 'Error Combine' is not a member of 'String'
            PictureBox3.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME3"))) 'Error Combine' is not a member of 'String'
            PictureBox4.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME4"))) 'Error Combine' is not a member of 'String'
            PictureBox5.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME5"))) 'Error Combine' is not a member of 'String'
            PictureBox6.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME6"))) 'Error Combine' is not a member of 'String'
        End Sub
    Last edited by roy88; Jan 12th, 2022 at 09:56 PM.

Tags for this Thread

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