0

I have a datagridview filled with data. Now I want to display the image of the selected data to a picture box. The code works with text and dates no matter what data i click it changes but not on image. I got a error message 'Unable to cast object type 'System.Byte[]' to type System.Drawing.Image ' Sample code below

Private Sub selected()
 Private Sub selected()Try
        If Me.dgvadt.Rows.Count > 0 Then
            If Me.dgvadt.SelectedRows.Count > 0 Then

                If Me.dgvadt.SelectedRows(0).Cells("idComplaints").Value Is DBNull.Value = True Then
                    Me.txtIDcomplaint.Text = ""
                Else
                    Me.txtIDcomplaint.Text = Me.dgvadt.SelectedRows(0).Cells("idComplaints").Value
                End If

                If Me.dgvadt.SelectedRows(0).Cells("DateFiled").Value Is DBNull.Value = True Then
                    Me.txtDF.Text = ""
                Else
                    Me.txtDF.Text = Me.dgvadt.SelectedRows(0).Cells("DateFiled").Value
                End If

                If Me.dgvadt.SelectedRows(0).Cells("AccountNumber").Value Is DBNull.Value = True Then
                    Me.txtAC.Text = ""
                Else
                    Me.txtAC.Text = Me.dgvadt.SelectedRows(0).Cells("AccountNumber").Value
                End If

                      If Me.dgvadt.SelectedRows(0).Cells("Attachment").Value Is DBNull.Value = True Then

                Else
                    pbPicture.Image = Me.dgvadt.SelectedRows(0).Cells("Attachment").Value
                End If

            End If
        End If

    Catch ex As Exception
        MsgBox(ex.Message)
        MessageBox.Show("Click to View", "PELCO III ", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Try
End Sub
  • It is not clear what `Me.dgvadt.SelectedRows(0).Cells("Attachment").Value` returns. I do not see anything in the code that involves a picture box. What have you tried? You may want to peruse… [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – JohnG May 16 '17 at 11:09
  • I updated the code – Nathaniel Nathan May 16 '17 at 13:05
  • this link could help you: http://stackoverflow.com/questions/9173904/byte-array-to-image-conversion Good luck – raBinn May 16 '17 at 13:08

0 Answers0