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
DataGridView1.Columns.Add(dgvImageColumn)
' 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")
DataGridView1.Rows.Add(img1)
Dim img2 As Image
img2 = Image.FromFile("D:\Images\img2.jpg")
DataGridView1.Rows.Add(img2)
Dim img3 As Image
img3 = Image.FromFile("D:\Images\img3.jpg")
DataGridView1.Rows.Add(img3)
Dim img4 As Image
img4 = Image.FromFile("D:\Images\img4.jpg")
DataGridView1.Rows.Add(img4)
Dim img5 As Image
img5 = Image.FromFile("D:\Images\img5.jpg")
DataGridView1.Rows.Add(img5)
End Sub
End Class
///////////////OUTPUT:
Display Images On datagridview |