2,892 questions
Hi
Simple example here my help. There are a couple of hard coded paths - you would need to edit accordingly if you want to try the example. You can drag the cell edges to resize.
Option Strict On
Option Explicit On
Public Class Form1
Dim dt As New DataTable("Freddy")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With dt
.Columns.Add("ID", GetType(Integer))
.Columns.Add("Image", GetType(Image))
.Columns.Add("Desc", GetType(String))
.Rows.Add(123, Image.FromFile("C:\Users\lesha\Documents\VB Resources\Images\ABS.jpg"), "Some words")
.Rows.Add(321, Image.FromFile("C:\Users\lesha\Documents\VB Resources\Images\Amedee Lighthouse.jpg"), "More words")
End With
With DataGridView1
.DataSource = dt
.AllowUserToAddRows = False
End With
End Sub
Private Sub DataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
If (e.RowIndex < 0 Or e.ColumnIndex < 0) Then Return
If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).ValueType = GetType(Image) Then
CType(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex),
DataGridViewImageCell).ImageLayout = DataGridViewImageCellLayout.Zoom
End If
End Sub
End Class