show images in datagridview from database
In C# windows application, i am uploading the images in folder and saving the folder path in database. Now i want to show the images in Datagridview in thumbnail and when clicking on thumbnail images they will open in big size. How i will do it.Please suggest me. Thanks in advance.
Satyapriya NayakPosted Sep 16, 2013, 9:27 AM
http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=78
http://johnroach.info/2012/01/13/how-to-add-images-to-datagridview-cell-using-c-and-windows-forms/
shital kothariPosted Jun 11, 2012, 6:36 PM
If you stores images in database then it would not be any problem to show the images in data grid view.
But now case is diff,
So you needs to create DataGridViewRow' object and after that you can add the rows to your data grid view.
Sorry, I do not have any editor installed with me, so understand any syntactical mistakes....
eg.
if (con.state== ConnectionState.Closed)
{
con.open();
}
cmd.connection=con;
cmd.commandText="select * from tablename"
dr=cmd.executeReader();
//dr is an instance of sqlDataReader or oledbDataReader
while(dr.read)
{
String picPath;
DatagridViewRow dgvr=new DataGridViewRow();
dgvr.cells[0].value=dr.getInt32(0); //ie. id
dgvr.cells[1].value=dr.getString(1); //ie. name
picPath=dr.getString(2); //ie. image path
Image newImage = Image.FromFile(picPath);
dgvr.cells[2].value=newImage; //create new object of System.Drawing.Image class
datagridViewobj.rows.add(dgvr); // add created row to datagridview
}
Thank you,
Shital Kothari,
Ocular Systems, Baramati,
website: http://www.ocularsystems.in
blog: http://ocularsystems.in/blog
[email protected]