Jose M.
Jose M.

Reputation: 2330

Sorting buttons on a FlowLayoutPanel

I have a FlowLayoutPanel that users add buttons dinamically. I worked out the code to add the buttons on the panel, the problem I have now is that my buttons are not sorted by name. Instead the buttons show up in the order they were created.

How can I sort the buttons automatically once a new button is created? Can this be done, or am I using the wrong type of panel?

Here is an image of the panel with my buttons, this one appears sorted because it was the initial panel I created.enter image description here

Upvotes: 2

Views: 1466

Answers (1)

LarsTech
LarsTech

Reputation: 81610

Use the SetChildIndex method of the Controls' collection:

flp.Controls.SetChildIndex(button3, 1);

Upvotes: 2

Related Questions