Where is WebListBox.headerPressed ?!

You’re probably wrong. DataSource is very fast. It’s designed for doing what you want in that the listbox requests just what it needs to display and gives the user the ability to scroll to anywhere in the list.

It does mean rethinking your query a little as an object that needs to be refreshed periodically however. I suggest that you create a class and apply the WebDataSource interface to it. Add a property to the class for the base query without the sorting ORDER BY or row filter LIMIT statements.

RowCount should only get recalculated on the first run or when the data has changed. It should return the total number of rows in the data set without filters.

RowData needs to run your query using the provided sort order and rows it asks for by adding a ORDER BY and LIMIT clause to your base query. Probably 20 at a time.

ColumnData should also only be recalculated on the first run and on data changes.

So what I mean here is you should put private properties on the class for storing the count and the column configuration and only recall those when they are zero or have zero elements, and make a refresh method that you call whenever the listbox data needs updating. You could even store a WeakRef to the listbox and have it also call the listbox’s refresh method after updating the query so you don’t have to remember.

It’s not hard, just a different way of thinking about it. It also makes it really easy to change the DataSource at runtime if you want to load different data depending on user choices.

2 Likes