Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping and ADO.Net Question

Status
Not open for further replies.

Cenedra

Programmer
Jan 2, 2003
114
US
Here is the code I have:

DataRow SavedGameRow = tbl.Rows[0];

for (x = 1; x < 10; x++)
{
switch (SavedGameRow[x])
{
case "X": pictureBox1.Image = "playerOne.Img"; break;
case "O": pictureBox1.Image = "playerTwo.Img"; break;
case "E": //Some code
break;

}

}

Is there a way that where the '1' is in the pictureBox1.Image = blahblah that I can use the X value in my loop without putting the picture boxes into an array and doing it like pictureBox[x] ?


Thanks for your help!
 
If pictureBox1, pictureBox2, ... objects are instances of a base class , let say MyPictureBox in which Image is a property then you can use a Hashtable like here:
Code:
Hashtable ht = new Hashtabble();
ht.Add("1", pictureBox1);
ht.Add("2",pictureBox2);
....
ht.Add("9"), pictureBox9);
for (int x = 1; x < 10; x++)
{
    if (ht.ContainsKey(x.ToString()))
     ((MyPictureBox)ht[x.ToString()]).Image = "C:\\Images\\MyFile" + x.ToString();
    else 
     // assign a default image
       
}
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top