Vishan S Gill

Vishan S Gill

  • NA
  • 15
  • 13.7k

Array of Labels

May 15 2011 11:37 AM
Hi Guys,

I've been looking through the internet for my kind of problem, but so far I could not find anything. I'm trying to add multiple labels dynamically in a loop into a Panel. Below is my code:

        labelArray = new Label[orderedFoodCount];
            for (int i = 0; i < orderedFoodCount; i++)
            {
                MessageBox.Show("round: " + i.ToString());
                labelArray[i] = new Label();
                labelArray[i].Name = "Label" + i.ToString() + "";
                labelArray[i].Location = new System.Drawing.Point(100, i + 40);
                panelSummary.Controls.Add(labelArray[i]);
                labelArray[i].Text = "Testing: " + i.ToString();
            }

It only shows me the first array, ie, labelArray[0]. Any idea why? I've checked the loop and it runs accordingly and shows me the counter in each run.

Thanks,

Vish

Answers (3)