jeudi 29 juin 2017

When progmatically adding elements through a loop, only the first one appears (C#)

I have a list of user defined "tags" stored in a list of strings called warehouse.tags. Using a basic for loop, I am creating checkboxes for each of the tags and adding them to a panel within a windows form.

The problem is that only the first checkbox shows up. I stepped through the code several times, and the location coordinates and other properties seem to be working. The problem does not seem to be that the checkbox location is outside the panel boundaries.

   for(int i = 0; i < warehouse.tags.Count; i++) //adds check boxes for each tag
        {
            CheckBox tagNameLabel = new CheckBox();
            tagNameLabel.Text = warehouse.tags.ElementAt(i);
            Point tagLabelPoint = new Point();
            tagLabelPoint.X = xAdjuster; // xadjuster = 25 in this case 
            tagLabelPoint.Y = (5 + yAdjuster) * (warehouse.categories.Count + 1); //yadjuster = 25 as well
            tagNameLabel.Location = tagLabelPoint;
            this.filterOptionsPanel.Controls.Add(tagNameLabel);

        }

Open to any ideas of what may be going wrong - thanks.




Aucun commentaire:

Enregistrer un commentaire