Info fastest listbox

Hello group, I have this question. I work on a listbox, I load the rows one at a time with all the necessary data … there are many rows for each table. I have 5 ListBoxes and to fill them I use something like this:

ListBox(indexListBox).RemoveAllRows
While Not Rows.AfterLastRow
  ListBox(indexListBox).AddRow(A,B,C,D,E,F,G)
  rows.MoveToNextRow
Wend

I wanted to know if there is any “trick” to speed up the display. I noticed that with so much data it takes a few seconds …

Try this, maybe it makes a little difference:

Var start As Integer = System.Ticks

' Set to False, speeds up the Routine
ListBox(indexListBox).Visible = False

ListBox(indexListBox).RemoveAllRows
While Not Rows.AfterLastRow
  ListBox(indexListBox).AddRow(A,B,C,D,E,F,G)
  rows.MoveToNextRow
Wend

' Reset
ListBox(indexListBox).Visible = True

Var ended As Double = (System.Ticks - start) / 60

System.DebugLog(ended.ToString + " seconds")
1 Like

A few things, why are you casting to ListBox all the time? ie “ListBox(indexListBox)”. Also with a tight loop like this try disabling background tasks:

#Pragma BackgroundTasks False
Var lb as ListBox = ListBox(indexListBox)
lb.RemoveAllRows
While Not Rows.AfterLastRow
  lb.AddRow(A,B,C,D,E,F,G)
  rows.MoveToNextRow
Wend
#Pragma BackgroundTasks True
1 Like

Thanks guys, I managed to lower the opening times by almost 1 second. P.S: I used the trick of the Visible in VB6 :slight_smile:

How many Rows ?

If “so much data”, you may feed the ListBoxes “on demand” (only some Rows at the time; say 50 Rows at a time - enough to fill the window)…

Actually it is variable, it can go from 300 to 16000 lines … but by examining the code better I solved some repetition problems and with the two help of friends above, I greatly speeded up the display. For me it’s ok and it can go.

If it’s OK for you to load / fill all 16 000 Rows… But it does not make sense to do so.

for a single column there should be . AddRows
it fill in one step from array.

or see blog
Lazy Loading Data with ListBox

This ^^^

??

I meant that your question as to why the OP feels the need to cast his ListBox was a good one, deserving of an answer.

Ah, I thought you were providing an answer and failed to provide a link or some such. :slight_smile:

Yeah, I should have added ^^^^ to show what I was referring to :slight_smile:

1 Like