i want to display the images in one dirctoryin which the files areall imagesin the DataGridView?Could somebody give me some instructions or tips?Thank you so much!!!
wilbyang Wednesday, August 19, 2009 3:53 PM
//Create one DataGridViewImageColumn and add to DataGridView1
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
imageColumn.Name = "Image";
imageColumn.HeaderText = "Show Image";
DataGridView1.Columns.Add(imageColumn);
//get image files
DirectoryInfo di = new DirectoryInfo(/*directory path*/);
FileInfo[] images = di.GetFiles("*.jpg");
// Assign thumbnails images to each cell of DataGridViewImageColumn
DataGridView1.RowCount =images.Length;
for (int i = 0; i <= DataGridView1.RowCount - 1; i++)
{
DataGridView1.Rows[i].Cells[0].Value = Image.FromFile(images[i].FullName);
}
Marked As Answer bywilbyangThursday, August 20, 2009 4:19 PM
NareshG Wednesday, August 19, 2009 7:57 PM
//Create one DataGridViewImageColumn and add to DataGridView1
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
imageColumn.Name = "Image";
imageColumn.HeaderText = "Show Image";
DataGridView1.Columns.Add(imageColumn);
//get image files
DirectoryInfo di = new DirectoryInfo(/*directory path*/);
FileInfo[] images = di.GetFiles("*.jpg");
// Assign thumbnails images to each cell of DataGridViewImageColumn
DataGridView1.RowCount =images.Length;
for (int i = 0; i <= DataGridView1.RowCount - 1; i++)
{
DataGridView1.Rows[i].Cells[0].Value = Image.FromFile(images[i].FullName);
}
Marked As Answer bywilbyangThursday, August 20, 2009 4:19 PM
NareshG Wednesday, August 19, 2009 7:57 PM
thank you so much!!!
wilbyang Thursday, August 20, 2009 4:24 PM
which method or eventhandler of the DataGridView should i put the above codes in?
wilbyang Thursday, August 20, 2009 4:36 PM
Its depends when you need to display images in datagridview. If you need to display as form show, then you can use Form_Load event.
NareshG Thursday, August 20, 2009 5:13 PM
thank you so much for your help.the images did display in the DataGridView.as i ama novice to dot net windows app development,i've no ideahow to set the size(the width and the heighth) for each image to display.could you give me somemore advice?