Flicker when updating Listbox

R

Reg Verrin

I have a program that displays constantly changing prices which it
sources from the web once per second. The prices are displayed on a
Listbox (not the best choice but there are good reasons for this).

The Listbox flickers when updating and I can't find a solution on the
net.

Here is the code:

'update Listbox
listPrices.SuspendLayout()
For n = 1 To 20
LineStr = Space(16)

Mid(LineStr, 1, 10) = PriceData(n).ItemID
Mid(LineStr, 13, 4) = PriceData(n).ItemPrice

listPrices.Items(n - 1) = LineStr 'the fault is probably
here
Next n
listPrices.ResumeLayout()

I'm using VB 2005 Express.

Someone with a similar problem was advised to use SuspendLayout and
ResumeLayout and, as you can see, I tried that but it didn't help.

Any ideas?
 
R

rowe_newsgroups

I have a program that displays constantly changing prices which it
sources from the web once per second. The prices are displayed on a
Listbox (not the best choice but there are good reasons for this).

The Listbox flickers when updating and I can't find a solution on the
net.

Here is the code:

'update Listbox
listPrices.SuspendLayout()
For n = 1 To 20
        LineStr = Space(16)

        Mid(LineStr, 1, 10) = PriceData(n).ItemID
        Mid(LineStr, 13, 4) = PriceData(n).ItemPrice

        listPrices.Items(n - 1) = LineStr   'the fault is probably
here
Next n
listPrices.ResumeLayout()

I'm using VB 2005 Express.

Someone with a similar problem was advised to use SuspendLayout and
ResumeLayout and, as you can see, I tried that but it didn't help.

Any ideas?

What I used to do to handle a similar situation was to override
WndProc and intercept the WM_PAINT messages. Then, I could turn on or
off the painting during the update and then turn it back on
afterwards.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
A

Armin Zingler

Reg Verrin said:
I have a program that displays constantly changing prices which it
sources from the web once per second. The prices are displayed on a
Listbox (not the best choice but there are good reasons for this).

The Listbox flickers when updating and I can't find a solution on
the net.

Here is the code:

'update Listbox
listPrices.SuspendLayout()
For n = 1 To 20
LineStr = Space(16)

Mid(LineStr, 1, 10) = PriceData(n).ItemID
Mid(LineStr, 13, 4) = PriceData(n).ItemPrice

listPrices.Items(n - 1) = LineStr 'the fault is probably
here
Next n
listPrices.ResumeLayout()

I'm using VB 2005 Express.

Someone with a similar problem was advised to use SuspendLayout and
ResumeLayout and, as you can see, I tried that but it didn't help.

listPrices.BeginUpdate
...
listPrices.EndUpdate

?

I think there is no layout with a Listbox.


Armin
 
A

Alex Clark

Hi Reg,

First off, SuspendLayout won't be doing anything for you - this simply holds
off running layout code (i.e. anchors, docking etc) and as the ListBox isn't
a ContainerControl it won't help with performance.

BeginUpdate/EndUpdate are good candidates, and probably do the same thing as
the Win32 API call of "LockWindowUpdate" which prevents painting until you
tell it otherwise.

One other thing I would suggest: Instead of adding listbox items
one-at-a-time during your For n loop, build up an array of them. Then at
the end of the loop, clear the listbox items and then do a .AddRange call
with your array of new items. That should speed things up a little also.

-Alex
 
R

Reg Verrin

Thank you all for taking the time to help.

Unfortunately, BeginUpdate/EndUpdate doesn't help.

I would appreciate a coding example of how to either intercept the
WM_PAINT messages or use LockWindowUpdate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top