Wednesday, October 21, 2009

Add image in Datagridview

Dim img As New DataGridViewImageColumn
With img
.DataPropertyName = "Picture"
.HeaderText = "Picture"
.Width = 20
' Specify path to a directory where image files are stored
.Image = ImageList1.Images(0)
End With
DataGridView1.Columns.Insert(0, img)

**************** update image dynamically ****************
If DataGridView1.Rows.Count = 0 Then
DataGridView1.Rows.Insert(0)
End If

With DataGridView1.Rows(0)
.Cells(0).Value = ImageList1.Images(iconImg)
.Cells(1).Value = strValue
End With
DataGridView1.Refresh()