Torna al Thread
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'---- qui carico da una dir di esempio i file jpeg
Dim dirInfo As New DirectoryInfo("C:\Users\Matteo\Pictures")
DataGridView1.DataSource = dirInfo.GetFiles("*.jpg")
DataGridView1.Columns.Insert(0, New MiaColonnaImmagine())
End Sub
Private Class MiaColonnaImmagine
Inherits DataGridViewImageColumn
Public Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell
Get
Return New MiaCellaImmagine() '----- qui gli dico che uso la mia classe che dara' un valore diverso dallo standard
End Get
Set(ByVal value As System.Windows.Forms.DataGridViewCell)
MyBase.CellTemplate = value
End Set
End Property
End Class
Private Class MiaCellaImmagine
Inherits DataGridViewImageCell
Protected Overrides Function GetFormattedValue(ByVal value As Object, ByVal rowIndex As Integer, ByRef cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal valueTypeConverter As System.ComponentModel.TypeConverter, ByVal formattedValueTypeConverter As System.ComponentModel.TypeConverter, ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object
'----- nel tuo caso avrai gia' i record pronti con il path, qui invece vado a prendermi un FileInfo perche' avevo bindato quello alla griglia
Dim file As FileInfo = Me.DataGridView.Rows(rowIndex).DataBoundItem
If file Is Nothing Then
Return Nothing
Else
Return Image.FromFile(file.FullName) '---- torno l'immagine letta dal path, tanto la colonna è cmq di tipo immagine
End If
End Function
End Class