使用 DevExpress.Utils 或其他路径组合在 vb.net 中的解决方案,在使用 devexpress gridview 的图片编辑中显示图像

Show Images in picture edit with devexpress gridview with DevExpress.Utils or other solutions with paths combined in vb.net

我无法在图片编辑中显示图像,可能是因为我的代码不正确,或者有其他最好的解决方案或建议。 或者还有另一种方法,即使文件名在子文件夹中,也可以将父路径文件夹和文件名组合起来,以便它可以显示图像。

for information
filePath1 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\ART RANDOM TAMAKA8108(1).jpg
filePath1 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\ART RANDOM TAMAKA8108(2).jpg
filePath2 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\CATALOG MOLFON 2015\SLONG08012(1).jpg
filePath2 : C:\Users\ADMIN2\Desktop\CATALOG FINAL2\CATALOG MOLFON 2015\SLONG08012(6).jpg

谢谢 杰克

Capturegridview22022022

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

访问https://docs.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Base.ColumnView.GetFocusedRowCellValue(System.String)

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