By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,277 Members | 1,433 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,277 IT Pros & Developers. It's quick & easy.

Flicker when updating Listbox

P: n/a
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?
Jul 14 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jul 14, 10:43*am, 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 = 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/
Jul 14 '08 #2

P: n/a
"Reg Verrin" <re*@yingtongtiddleipoyaknow.comschrieb
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
Jul 14 '08 #3

P: n/a
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" <re*@yingtongtiddleipoyaknow.comwrote in message
news:q2**************************@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?

Jul 14 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.