Sorting container controls

I’m struggling to sort dynamically generated container controls in a web app.

All controllers have a property like “ID” and for a single “addition” of container controls the IDs could be “O”, “A”, “I”, “M”, “UP”, “H”, “UP”, “N”, “”, “UP”.
There will always only be one of the single character-ID’s but there can be an unknown number of “UP’s”.
The single characters should be sorted alphabetically and all of the UP’s should come last.
I’ve been thinking of putting the container controls in an array and sort the array like it’s described here: under “Sorting Arrays of Classes” but that does not solve the problem with the “UP’s”.

Any ideas?

  • Define a property of the container controls where you define a sort priority. Assign priority 1 to those containers that need to come on top, priority 9 to those (like the UP) that need to come on the bottom.
  • Define a second property that concatenates the new property and the one that you are using now, and then sort according to this new property. That should do the trick, with one or the other solutions that you already explored.

This is a general idea, someone is bound to come up with a better and more elegant solution…

A quick’n’dirty way would be:

  1. Create an array of ID for each container control (let’s call it IDS)
  2. Replace all occurrences of “UP” to something that will always be sorted last (like “ZZZ”)
  3. Use SortWith to sort IDS and your container controls’ array

Two usable solutions in less than half an hour!!
This forum rocks — as always :slight_smile:

I am not at my computer right now. Will mark the solution when I’ve decided which one I end up using.

Thank you