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