tips
[Top] [All Lists]

REALbasic Tip: Improve the speed of adding rows to a listbox by 10 times

To: "REALbasic Tips" <realbasic-tips at lists dot realsoftware dot com>
Subject: REALbasic Tip: Improve the speed of adding rows to a listbox by 10 times
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Fri, 13 Sep 2002 11:54:17 -0500
There's an easy way to reduce the time it takes to add a large number of
rows to a listbox.

Hide the listbox by setting its visible property to false before the loop
that adds the rows and then set it back to true when you are finished.
Consider the following example:

  dim i as integer
  for i = 1 to 1000
    ListBox1.addrow str(i)
  next

On my Mac it takes 20 ticks to execute this loop. If I make the listbox
invisible before adding the rows and then make it visible again afterwards,
the code takes only 2 ticks. That's a 10 fold increase in performance!

Here's the example again with the additional code:

  dim i as integer
  ListBox1.Visible = false
  for i = 1 to 1000
    ListBox1.addrow str(i)
  next
  ListBox1.Visible = true

Why does hiding the listbox make it faster? REALbasic redraws the listbox each time the AddRow method is called. It doesn't know whether you need it
redrawn or not. This redraw takes time. When the listbox is not visible,
REALbasic doesn't bother to redraw it.

Thanks to Ryan Dary for inspiring this tip.

If you use listboxes extensively in your apps, make sure you look at
REALbasic v4.5. With this new version, you can give your users listboxes
with resizable columns and the ability to drag rows to reorder them.

If you haven't upgraded to REALbasic v4.5, you can do so here:
<http://www.realsoftware.com/store/index.html>
--
Geoff Perlman
President and CEO
REAL Software, Inc.
512-328-7325 x711 (voice)
512-328-7372 (fax)


 - - - - - - - - - -
Got a useful tip to share? Send it to us at:
REALbasic-tips at lists dot realsoftware dot com dot
To unsubscribe from the Tips list, send an email to
<mailto:realbasic-tips-off at lists dot realsoftware dot com>


<Prev in Thread] Current Thread [Next in Thread>
  • REALbasic Tip: Improve the speed of adding rows to a listbox by 10 times, Geoff Perlman <=