Visual Basic: Load images into datagridview

Platform:Visual Basic
Task:Load images into datagridview
Discussion:
Load images into datagridview
Example:
    Private Sub LoadImagesGrid()
        txtDirectory.Text = CurrentDirectory
        ImagesDataGridView.Rows.Clear()
        For Each FileToLoad In My.Computer.FileSystem.GetFiles(CurrentDirectory)
            If My.Computer.FileSystem.GetFileInfo(FileToLoad).Extension = ".jpg" Then
                '---create a row---
                Dim NewRow As New DataGridViewRow
                NewRow.CreateCells(ImagesDataGridView)
                Dim TheImage As New Bitmap(FileToLoad)
                Dim TheImageThumbnail As Image = TheImage.GetThumbnailImage(100, 100, Nothing, Nothing)
                With NewRow
                    .Cells(0).Value = TheImageThumbnail
                    .Cells(1).Value = FileToLoad
                End With
                '---add the row---
                ImagesDataGridView.Rows.Add(NewRow)
            End If
        Next
    End Sub
Back to Index