VB.NET - How To Populate DataGridView With Images In VB

datagridview column images

VB.NET - How To Bind DataGridView With Images Using VBNET 


In This Visual Basic Tutorial We Will See How To Show / Display Images In DataGridView Using VB.NET Programming Language.

Project Source Code:

Public Class Populate_Datagridview_With_Images_VB

    Private Sub Populate_Datagridview_With_Images_VB_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        '  Create Datagridview image column
        Dim dgvImageColumn As New DataGridViewImageColumn
        ' set header text to the colun
        dgvImageColumn.HeaderText = "Image"
        ' make the image layout stretch to display the entire image
        dgvImageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
        ' add the column to the datagridview
        ' make the columns take all the datagridview width
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        ' change the datagridview height
        DataGridView1.RowTemplate.Height = 150

        DataGridView1.AllowUserToAddRows = False

        ' create images and add the to the datagridview
        Dim img1 As Image
        img1 = Image.FromFile("D:\Images\img1.jpg")

        Dim img2 As Image
        img2 = Image.FromFile("D:\Images\img2.jpg")

        Dim img3 As Image
        img3 = Image.FromFile("D:\Images\img3.jpg")

        Dim img4 As Image
        img4 = Image.FromFile("D:\Images\img4.jpg")

        Dim img5 As Image
        img5 = Image.FromFile("D:\Images\img5.jpg")

    End Sub
End Class


bind datagridview with images
Display Images On datagridview

Share this

Related Posts

Next Post »