Hi,
I am using the ultraFlowLayout control on my form. When I add a number of controls on to the panel, they are placed in the wrong order. If I try to move a control innside the panel, it snaps back to it's original place.
How do I change the order of the controls innside a panel that is controlled by ultraFlowLayoutManager?
Thanks in advance
Hello,
The FlowLayoutManager orders the controls based off of the order in which they were added to the container that is being managed. The easiest way to reorder the controls is to go in to the designer code and change the add order of the controls.
Is there anyway to accomplish this at run-time? I need to order the controls based on the user defined order that is stored in the database.
It might be thread-necromancy, but as I was also stuck with this, here's my solution for the developers out there struggling with this issue:
The contents of a container control can usually be found in the container.Controls property. That has an AddRange() method that takes a collection of Controls as parameter. The FlowLayoutManager does not do any sorting, but keeps the order in which the items were added. So I ended up with ordering the items the following way: I made a List<Control> instance, added the required controls in the required order (I had to do a bottom-up order with some inserting here and there, a list seemed the perfect choice) then exported them as an array for AddRange() with the List.CopyTo() method. So the final code looks something like this:
private var controlList = new List<Control>();private var anUltraPanel = new UltraPanel();private var aFlowLayoutManager = new UltraFlowLayoutManager();[...]private void createReverseUltraFlowLayout() {this.controlList.Insert(0, item1);this.controlList.Insert(0, item2);this.controlList.Insert(1, item3);this.anUltraPanel.ClientArea.Controls.Clear();Control[] controlArray = new Control[this.controlList.Count];this.controlList.CopyTo(controlArray, 0);this.anUltraPanel.ClientArea.Controls.AddRange(controlArray);}
and the output should be something like this:
Item2Item3Item1
The Clear() and AddRange() solution might not be optimal, but that's the best I could come up with.