Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a Control to Beginning of a FlowLayoutPanel

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.

like image 236
Hawkeye Avatar asked Nov 04 '25 11:11

Hawkeye


1 Answers

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()
like image 182
LarsTech Avatar answered Nov 07 '25 08:11

LarsTech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!