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?

Re: Flicker when updating Listbox by rowe_newsgroups

rowe_newsgroups
Mon Jul 14 11:02:38 CDT 2008

On Jul 14, 10:43=A0am, Reg Verrin <r...@yingtongtiddleipoyaknow.com>
wrote:
> 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 =3D 1 To 20
> =A0 =A0 =A0 =A0 LineStr =3D Space(16)
>
> =A0 =A0 =A0 =A0 Mid(LineStr, 1, 10) =3D PriceData(n).ItemID
> =A0 =A0 =A0 =A0 Mid(LineStr, 13, 4) =3D PriceData(n).ItemPrice
>
> =A0 =A0 =A0 =A0 listPrices.Items(n - 1) =3D LineStr =A0 'the fault is pro=
bably
> 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/

Re: Flicker when updating Listbox by Armin

Armin
Mon Jul 14 11:47:51 CDT 2008

"Reg Verrin" <reg@yingtongtiddleipoyaknow.com> schrieb
> 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

Re: Flicker when updating Listbox by Alex

Alex
Mon Jul 14 16:16:45 CDT 2008

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


"Reg Verrin" <reg@yingtongtiddleipoyaknow.com> wrote in message
news:q2V7SNStedaKceBaaSMcEjOT0dJs@4ax.com...
>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?