Optimizing my custom ListBox


So, I decided to ditch the ListBox control and create my own with Canvas, ScrollBar and embedded ContainerControls as rows. Now that it’s finally ready and I’ve began testing it, I’m seeing that it has slowed down the UI of my app considerably, especially when there are like 100 rows. For example resizing the window is very sluggish. Can anyone give me some optimization tips on how I could make it faster? I know it might be hard not seeing the actual code, but I’ll appreciate all ideas what I could do in this situation.

Lazy loading :slight_smile: only display the rows that can actually be seen by the user. Dynamically load more on scrolling…

Turn on the Profiler, see what’s taking the most time and focus on that.

You should avoid creating ContainerControls, because this takes a lot of time, especially if they have a lot of controls in them. So creating 100 rows by creating 100 ContainerControls is not such a good idea. For example Mac OS X introduced view-based NSTableViews only with Lion in 2011, prior to 2011 you had to use cell-based ones (view-based NSTableView is the equivalent to you idea, cell-based is the equivalent to Xojo’s Listbox).

You should therefor try to create only as much ContainerControls as are visible - plus 1 more - and then reuse the disappearing one on the other end of the listbox when scrolling.

Resizing might be slow because of too much repainting going on (perhaps also for a lot of invisible rows).
Don’t use Refresh() on the controls in the rows - use Invalidate().
Don’t have any controls overlapping other ones.

A completely different idea: Try to get rid of the ContainerControls as rows and work with ControlSets, where all controls with index 0 represent row 0, all controls with index 1 represent row 1, etc. It might be faster, but that’s a shot in the very dark…


how do i accomplish this??

Thanks for the suggestions! Lukas, have you successfully implemented that “reusing” technique you are talking about? I would love to see a snippet of that code.

I also did a little test with Control Sets, but they too made the app sluggish. Not with as little amount of rows, but still.