1
votes

I'm trying to make a list of controls. For this, I used a flow layout panel and a custom item. After reading a XML file I populate the flow layout panel with my items. For a small number of items everything seams to be OK but for a number like 371 of items in the flow layout panel something get's wrong. At the bottom of the flow layout panel 95 items are missing, and seams to be overlapped. The space located for this items, i think, is still created. I attach a screen with the effect produced. The controls are created in an array and then I iterate that array to add the controls to the flow layout panel.

http://img510.imageshack.us/img510/3201/screen2011916213527199.jpg

Thank you.

LE:

public delegate void AddHistoryItemDelegate(Control itm);
        public void AddHistoryItem(Control itm)
        {
            if (InvokeRequired)
            {
                Invoke(new AddHistoryItemDelegate(AddHistoryItem), new object[] { itm });
            }
            else
            {
                flowLayoutPanel1.Controls.Add(itm);
            }
        }
foreach (Control c in histroryItems)
            {
                controls++;
                backgroundWorkerLoadHistory.ReportProgress(controls);
                //flowLayoutPanel1.Controls.Add(c);
                AddHistoryItem(c);
            }

The delegate is there because all this is taking place in a separate thread. histroryItems is a List of controls.

LE: If it's counts, i observed that, if I remove an item from the list, after the list loads, it get's arranged. Trying a little hack to see if adding and removing a control at the end of the thread, does not have any effect.

2
C# does not have a FlowPanel. Or any Conbtrols.Henk Holterman
is about FlowLayoutPanel in Winforms. Sorry for the missing tags.andySF

2 Answers

3
votes

You could try this:

        this.flowLayoutPanel1.SuspendLayout();

before adding controls and:

        this.flowLayoutPanel1.ResumeLayout();

after adding controls. Maybe the following should be performed consecutively:

        this.flowLayoutPanel1.PerformLayout();

and/or:

        this.flowLayoutPanel1.Refresh();
1
votes

I found that I had to do this:

private void flpChoices_Scroll(object sender, ScrollEventArgs e)
{
   Control c=flpChoices.GetChildAtPoint(new Point(10, 10), GetChildAtPointSkip.None);
   if (c == null) flpChoices.PerformLayout();
}

Where flpChoices is my FlowLayout Panel. Now I don't think the scroll event is triggered on mouse wheel movement, so I don't know what to do about that.

EDIT: There is a hidden(not in the property window) even for scroll wheel:

void flpChoices_MouseWheel(object sender, MouseEventArgs e)
{
  Control c=flpChoices.GetChildAtPoint(new Point(10, 10), GetChildAtPointSkip.None);
  if (c == null) flpChoices.PerformLayout();

}