4

I have a program that grabs product data and adds a custom control for each record to a FlowLayoutPanel.

I would like to add a control to the beginning of the FlowLayoutPanel, as opposed to the end, to appear as the first item.

Does anyone have an idea how this is done? I would like to avoid having to repopulate it every time I add an item to the beginning.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Hawkeye
  • 578
  • 8
  • 20

1 Answers1

7

You can use the SetChildIndex method of the FlowLayoutPanel's Control collection:

Dim newButton As New Button With {.Text = flp.Controls.Count.ToString}
flp.SuspendLayout()
flp.Controls.Add(newButton)
flp.Controls.SetChildIndex(newButton, 0)
flp.ResumeLayout()
LarsTech
  • 80,625
  • 14
  • 153
  • 225