I'm trying to get some Data into my Datagridview with a For-Loop
But the thing is, my Loop jumps out if my counter is at 2 for no reason and I dont know why
This is my Code:
var row = new DataGridViewRow();
//image directory
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\Daniel\Pictures");
//getting all files from the Directory
foreach(FileInfo file in dir.GetFiles())
{
try
{
this.img16x16.Images.Add(Image.FromFile(file.FullName));
}catch
{
Console.WriteLine("This is not an image file");
}
}
for (int j = 0; j <= this.img16x16.Images.Count; j++)
{
dataGridView1.Rows[j].Cells[0].Value = img16x16.Images[j].ToString();
img16x16.ImageSize = new Size(16, 16);
dataGridView1.Rows[j].Cells[1].Value = img16x16.Images[j];
dataGridView1.Rows.Add(row);
Thanks for your help
edit: I found the solution, i just had to put these 2:
var row = new DataGridViewRow();
dataGridView1.Rows.Add(row);
in front of my code inside the for-loop