Ok, ok...this may be fun...
The problem is quite simple, but it may take a little explaining.
Lets simplify your code a bit...
int myInt = 0;
for (int i = 0; i < 5; i++)
{
myInt = i;
}
What would you expect that code to do? And how would it differ from:
int myInt = 5 - 1;
Your code does the same thing. It reads a collection of image names from teh DB, then it converts them to Images, and assigns them one after the other to your picture box. Just like with an
int
, the picture box ends up with just the final value, as if your loop did not exist.
So, change your code to:
Set up a class level List of strings, and clear it before you enter your loop.
Set a class level integer to index it.
In the loop, instead of creating an image, add the name to the List.
After the loop, set the index to zero.
Now, add a Timer to your form, which has an Interval suitable for switching images.
In the Tick event handler, check the index - if it is greater than or equal to the List.Count do nothing.
Otherwise, get the List item and the index, and increment the index for next time.
Now get the Image, and set the PictureBox.Image property.