I haven't been able to display the image in the picture edit probably because my code isn't correct or there's another solution or recommendation that's best. or there is another way by combining the parent path folder and filename even though the filename is in the subfolder so that it can display the image.
for information
filePath1 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\ART RANDOM TAMAKA\888108(1).jpg
filePath1 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\ART RANDOM TAMAKA\888108(2).jpg
filePath2 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\CATALOG MOLFON 2015\SLONG\1908012(1).jpg
filePath2 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\CATALOG MOLFON 2015\SLONG\1908012(6).jpg
Thanks jack
Public Class Form1
Private WithEvents dt As New DataTable
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PRODUCT2.mdb"
Private parentpathimage As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\CATALOG FINAL2"
Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path
Private Images As Hashtable = New Hashtable()
Private Sub LoadDataGridView()
Try
'Dim dt = New DataTable()
dt = New DataTable
Dim query = "select Code,Filename1,Filename2,SUBFOLDERP FROM ITEM"
Using adapter As New OleDbDataAdapter(query, cn.ToString)
adapter.Fill(dt)
End Using
Me.GridControl1.DataSource = dt
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadDataGridView()
End Sub
Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
Dim view As GridView = TryCast(sender, GridView)
Dim SUBFOLDERP As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.RowHandle, "SUBFOLDERP")) Then
SUBFOLDERP = CStr(view.GetListSourceRowCellValue(e.RowHandle, "SUBFOLDERP"))
Else
SUBFOLDERP = String.Empty
If e.Column.FieldName = "Filename1" Then
Dim Filename1 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
Dim filePath1 As String = DevExpress.Utils.FilesHelper.FindingFileName(parentpathimage & SUBFOLDERP, Filename1, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(filePath1)), True, False)
Else
If e.Column.FieldName = "Filename2" Then
Dim Filename2 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
Dim filePath2 As String = DevExpress.Utils.FilesHelper.FindingFileName(parentpathimage & SUBFOLDERP, Filename2, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(filePath2)), True, False)
End If
End If
End If
End Sub
End Class
CodePudding user response:
Public Class Form1
Private WithEvents dt As New DataTable
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PRODUCT2.mdb"
Private parentpathimage As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\CATALOG FINAL2"
Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path
Private Images As Hashtable = New Hashtable()
Private Sub LoadDataGridView()
Try
'Dim dt = New DataTable()
dt = New DataTable
Dim query = "select Code,Filename1,Filename2,SUBFOLDERP FROM ITEM"
Using adapter As New OleDbDataAdapter(query, cn.ToString)
adapter.Fill(dt)
End Using
Me.GridControl1.DataSource = dt
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadDataGridView()
End Sub
Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
Dim view As GridView = TryCast(sender, GridView)
***Dim SUBFOLDERP As String = view.GetFocusedRowCellValue("SUBFOLDERP").ToString***
If e.Column.FieldName = "Filename1" Then
Dim Filename1 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
Dim filePath1 As String = DevExpress.Utils.FilesHelper.FindingFileName(parentpathimage & SUBFOLDERP, Filename1, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(filePath1)), True, False)
Else
If e.Column.FieldName = "Filename2" Then
Dim Filename2 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
Dim filePath2 As String = DevExpress.Utils.FilesHelper.FindingFileName(parentpathimage & SUBFOLDERP, Filename2, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(filePath2)), True, False)
End If
End If
End Sub
End Class