Refresh The Canvas After Sort

I have a canvas with a bunch of embedded container control instances, and a property as an array storing a reference to each instance.

I am successfully able to sort the property array using the SortWith command. My debugger shows the property array in the new sort order.

My question is how do I now repopulate the canvas with my new sort order? I have tried a bunch of different things with no luck and was hoping there was an easy solution. Thanks!

what is it about the container controls that is changing as a result of the sort?
unless you change the LEFT and/or TOP values they won’t move

Well it’s that I want them to change to reflect the new sort. So I have a canvas with 5 container instances lined up in order like a list (top to bottom), 1,2,3,4,5. Each instance has a unique piece of data, say a person’s name. Now I want to re-sort, for example, so it displays a new order 2,4,5,3,1. I need the canvas to update the containers accordingly. Or wipe itself clean and redraw each instance in the new order. Or some other way. Not sure the best approach here.

I guess I am wondering is there a way to shuffle the data without clearing the canvas first. And if I do need to clear it, is there another method other that using “close” on my containers since that also erases the reference in the property array.

If these are in fact container objects using the canvas as a bounding control… then just adjust the top/left coordinates and they will move… no need to “redraw” anything

Of course the canvas redraws - don’t confuse matters.

The canvas just draws what and where you tell it to draw. Just change the properties of the embedded controls and call canvas1.invalidate (to make the canvas redraw at the next opportunity) and they are drawn at their new location.

If you have objects on a canvas… then Invaildating the canvas does nothing but call its PAINT event… which doesn’t affect the “objects” (be they container controls, textfields or buttons)… each of those objects control there own position, the canvas is just a “bounding box”

Thanks you guys - Markus I did try invalidate and to Dave’s point nothing much happened. Based on Dave’s advice I looped through my array with a ‘for’ loop, adjusting the ‘top’ of each container and voila! The canvas responded and my containers showed up in the newly-sorted order! 4 lines of code = one day of hair pulling. Thank you!!!