Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

database - How display images in datagridview? c#

I am developing an application in C # for desktop using Visual Studio Express 2010.

I have a table in MySQL called Products with 3 fields:

ID -> Product_Name -> product_image

The field product_Image stores the image path in my hard drive (not the image itself)

An example of a record would be:

0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg

I wonder how fill a datagridview that shows the ID, Produt name, and - especially - the product image for each record in my SQL query.

All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.

Edit:

Thank you for help, but could not directly apply the solutions.

I already have a datagridview on my form, I have no need to create in runtime.

I need something like that (I'll write a generic way)

returnMySQL = "select * from products";

while (returnMySQL)
{
??? fill datagrid with ID, product name, product image
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use following Code:

Bitmap img;

img = new Bitmap(@"c:imagesmousepad.jpg");

// Create the DGV with an Image column

DataGridView dgv = new DataGridView();

this.Controls.Add(dgv);

DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

dgv.Columns.Add(imageCol);

// Add a row and set its value to the image

dgv.Rows.Add();

dgv.Rows[0].Cells[0].Value = img;

Referance LINK .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...