I'm using a MySql database with 2 fields: a dossiernumber and a field where I save the name and location of a image. I want to place a datagrid on my winform and show a image (thumbnail) in the first cell and the dossiernumber in the second cell, but can't get it working.
The pictures don't show and leave only missing picture link. I also can't place the picture in the first cell. This is what it looks like:
What is wrong?
This is the code I've written:
Imports MySql.Data.MySqlClient
Public Class Form1
'ALLES OM DATAGRID TE PLAATSEN
'GLOBALE DECLARATIES
Dim conString As String = "server=localhost;userid=root;database=testvehicle"
Dim con As New MySqlConnection(conString)
Dim cmd As MySqlCommand
Dim adapter As MySqlDataAdapter
Dim dt As New DataTable()
Private Sub Form1_GotFocus(sender As Object, e As EventArgs) Handles Me.GotFocus
retrieve()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 2
DataGridView1.Width = 410
'CONSTRUCT IMAGE COLUMN
Dim imgCol As DataGridViewImageColumn = New DataGridViewImageColumn()
DataGridView1.Columns(0).Name = "Image"
DataGridView1.Columns.Add(imgCol)
'CONSTRUCT DATA COLUMNS
DataGridView1.Columns(1).Name = "dossiernr"
DataGridView1.Columns(1).Width = 100
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect
End Sub
'ALLES OM DATAGRID TE VULLEN
'PROCEDURE POPULATE ROW
Private Sub populate(foto1 As String, product_dossiernr As String)
Dim row As String() = New String() {foto1, product_dossiernr}
'ADD ROW TO ROWS
DataGridView1.Rows.Add(row)
End Sub
'DATA ONTVANGEN
Private Sub retrieve()
DataGridView1.Rows.Clear()
'SQL STATEMENT
Dim sql As String = "SELECT foto1, product_dossiernr FROM producten ORDER BY product_dossiernr"
cmd = New MySqlCommand(sql, con)
'OPEN CON, RETRIEVE, FILL DATAGRID
Try
con.Open()
adapter = New MySqlDataAdapter(cmd)
adapter.Fill(dt)
For Each row In dt.Rows
populate(row(0), row(1))
Next
con.Close()
dt.Rows.Clear()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
'EINDE DATAGRID VULLEN
End Class