简体   繁体   中英

How to display picture in DataGridView in C#

I have a book database with some records. Each record have one book details with book name, book link, and book picture path.

I need to display records with book picture in Data Grid View control. I found example how to display picture in Data Grid View but can't find example than to display picture with others fields in each record.

I researched much but I can't find example like this.

You can use DataGridViewImageColumn to display image. Refer the below example:

dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";

string[] row = 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);

DataGridViewImageColumn img = new DataGridViewImageColumn();
Image image = Image.FromFile("Image Path");
img.Image = image;
dataGridView1.Columns.Add(img);
img.HeaderText = "Image";
img.Name = "img";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM