Reputation: 2330
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.
Upvotes: 2
Views: 1466
Reputation: 81610
Use the SetChildIndex method of the Controls' collection:
flp.Controls.SetChildIndex(button3, 1);
Upvotes: 2