Fastest way to create a listbox

I need to create a listbox with 10 columns and 26000 rows. Using the addrow function takes about 8 seconds. Is there a faster way to do this?

Do
  if NumberOfItems > ListBoxItemsServer.RowCount then ListBoxItemsServer.AddRow(str(ListBoxItemsServer.LastRowIndex+1),"","","","","","","","","","") else exit
loop

I suggest that you do not.

It takes ages to populate, and no user will want to scroll through 26000 rows.
What is the nature of the data?
You would usually be better off having a search box, and displaying matching records.

If you feel you must have a list that can scroll through 26000 rows:
iOS has a technique where the lists show maybe 10 items, and the 10 you see are fed and reused on demand by a data source.

You can simulate this with (say) a 10 row listbox, coupled with a vertical scrollbar.
Read your data into an array.
refresh the 10 row list with 10 items of data, based on the value of the scrollbar.

2 Likes

Maybe lazy loading is an option?

There is an example called ā€˜Lazy Loadingā€™ that comes with Xojo.

For web there is an example on how to use WebListbox with Datasource called ā€˜Listbox with a Datasourceā€™.

1 Like

In the meanwhile, deactivate the VerticalScrollbar while populating your Listbox.

2 Likes

Hi,

i was in a hurry and just had my Smartphone yesterday, so i could not explain or test it. :slight_smile:

Xojo has really (really) bad performance doing graphic stuff. By just adding a

ListBoxItemsServer.HasVerticalScrollbar = False

before your Code and

ListBoxItemsServer.HasVerticalScrollbar = True

after your Code, the Ticks count dropped from 611 Ticks (10.2 Seconds) down to 15 Ticks (0.3 Seconds). So it was more than 30 times faster.

Maybe thatā€™s enough ā€œoptimizationā€ and you donā€™t have to rewrite your Code?

As a side note

While NumberOfItems > ListBoxItemsServer.RowCount
  
  ListBoxItemsServer.AddRow ListBoxItemsServer.RowCount.ToString,"","","","","","","","","",""
  
Wend

would be easier to read and is not slower. :slight_smile:

And just for the fun, the fastest way to create a listbox is:

Var lb As New DesktopListBox

or by Drag&Drop :wink:

Link to above XML Project on Pastebin: https://pastebin.com/raw/WBsPPQUe

3 Likes