How to add image and text to datagridview cell
2 answers
try it
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).Name = "Product ID"
DataGridView1.Columns(1).Name = "Product Name"
DataGridView1.Columns(2).Name = "Product_Price"
Dim row As String() = New String() {"1", "Product 1", "1000"}
DataGridView1.Rows.Add(row)
row = New String() {"2", "Product 2", "2000"}
DataGridView1.Rows.Add(row)
row = New String() {"3", "Product 3", "3000"}
DataGridView1.Rows.Add(row)
row = New String() {"4", "Product 4", "4000"}
DataGridView1.Rows.Add(row)
Dim img As New DataGridViewImageColumn()
Dim inImg As Image = Image.FromFile("Image Path")
img.Image = inImg
DataGridView1.Columns.Add(img)
img.HeaderText = "Image"
img.Name = "img"
End Sub
End Class
0
source to share
You can dynamically convert a DataGridView cell to DataGridViewTextBoxCell()
and display a text value to that column. below is some sample code that gives you a basic idea.
Private Sub button1_Click(sender As Object, e As EventArgs)
dataGridView1.Rows(3).Cells("ImageCol") = New DataGridViewTextBoxCell()
dataGridView1.Rows(3).Cells("ImageCol").Value = "Hello.."
End Sub
0
source to share