'How to display image in pictureedit and picturebox when clicked in gridview devexpress in vb.net

I want to display images in picturedit and picturebox when I click on gridview devexpress. I want to display the image when the cell value clicked in the path1 column and path2 column in one pictureedit and one picturebox.

Public Class Form1
    Private WithEvents dt As New DataTable
    Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PRODUCT.mdb"
    Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path
    Private Images As Hashtable = New Hashtable()

    Private Sub LoadDataGridView()
        Try
            dt = New DataTable
            Dim query = "select Code,Path1,Path2 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 path1 As String = view.GetFocusedRowCellValue("Path1").ToString
        Dim path2 As String = view.GetFocusedRowCellValue("Path2").ToString
        PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
        PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
    End Sub
End Class

Capturegridview18022022

Captureerror18022022



Solution 1:[1]

Use Click event instead of RowCellClick

Private Sub GridView1_Click(sender As Object, e As RowCellClickEventArgs) Handles GridView1.Click
    Dim path1 As String = (GridView1.GetRowCellValue(GridView1.FocusedRowHandle,"Path1"))
    Dim path2 As String = (GridView1.GetRowCellValue(GridView1.FocusedRowHandle,"Path2"))
    PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
    PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FikretBa