|
-
Jan 12th, 2022, 09:52 PM
#3
Thread Starter
Lively Member
Re: Display Image From dataGridView to multi picturebox in VB.NET
 Originally Posted by jmcilhinney
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:
Private Sub BindingSource1_CurrentChanged(...) Handles BindingSource1.CurrentChanged
Dim currentRow = DirectCast(BindingSource1, DataRowView)
Dim folderPath = CStr(currentRow("PATH"))
PictureBox1.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME1")))
PictureBox2.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME2")))
PictureBox3.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME3")))
PictureBox4.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME4")))
PictureBox5.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME5")))
PictureBox6.ImageLocation = Path.Combine(folderPath, CStr(currentRow("FILENAME6")))
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|