I want to display each datagrid view row id matched jpg files to the grid view, The problem is showing the last row id matched image for all rows. how to fix below code?
I have modified the code below:
string cerNumber = "";
DataGridViewImageColumn img = new DataGridViewImageColumn();
Image image = Image.FromFile(@"Output\10032-2.jpg");
for (int i = 0; i < 100; i )
{
cerNumber = dataGridView1.Rows[i].Cells["No"].Value.ToString();
image = Image.FromFile(@"Output\" cerNumber ".jpg");
}
img.Image = resizeImage((image), new Size(40, 20));
dataGridView1.Columns.Add(img);
img.HeaderText = "Image";
img.Name = "img";
CodePudding user response:
Add the column once, then set the column value property to each image loaded in the loop
dataGridView1.Columns.Add(new DataGridViewImageColumn() { Name = "img", HeaderText = "Image" });
for (int i = 0; i < 100; i )
dataGridView1.Rows[i].Cells["img"].Value = resizeImage(Image.FromFile(System.IO.Path.Combine("Output", dataGridView1.Rows[i].Cells["No"].Value.ToString() ".jpg")), new Size(40, 20));