Flicker when updating Listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reg Verrin

    Flicker when updating Listbox

    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.Susp endLayout()
    For n = 1 To 20
    LineStr = Space(16)

    Mid(LineStr, 1, 10) = PriceData(n).It emID
    Mid(LineStr, 13, 4) = PriceData(n).It emPrice

    listPrices.Item s(n - 1) = LineStr 'the fault is probably
    here
    Next n
    listPrices.Resu meLayout()

    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?
  • rowe_newsgroups

    #2
    Re: Flicker when updating Listbox

    On Jul 14, 10:43 am, Reg Verrin <r...@yingtongt iddleipoyaknow. 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.Susp endLayout()
    For n = 1 To 20
            LineStr = Space(16)
    >
            Mid(LineStr, 1, 10) = PriceData(n).It emID
            Mid(LineStr, 13, 4) = PriceData(n).It emPrice
    >
            listPrices.Item s(n - 1) = LineStr   'the fault is probably
    here
    Next n
    listPrices.Resu meLayout()
    >
    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]

    Comment

    • Armin Zingler

      #3
      Re: Flicker when updating Listbox

      "Reg Verrin" <reg@yingtongti ddleipoyaknow.c omschrieb
      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.Susp endLayout()
      For n = 1 To 20
      LineStr = Space(16)
      >
      Mid(LineStr, 1, 10) = PriceData(n).It emID
      Mid(LineStr, 13, 4) = PriceData(n).It emPrice
      >
      listPrices.Item s(n - 1) = LineStr 'the fault is probably
      here
      Next n
      listPrices.Resu meLayout()
      >
      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.Begi nUpdate
      ...
      listPrices.EndU pdate

      ?

      I think there is no layout with a Listbox.


      Armin

      Comment

      • Alex Clark

        #4
        Re: Flicker when updating Listbox

        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 ContainerContro l it won't help with performance.

        BeginUpdate/EndUpdate are good candidates, and probably do the same thing as
        the Win32 API call of "LockWindowUpda te" 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@yingtongti ddleipoyaknow.c omwrote in message
        news:q2V7SNSted aKceBaaSMcEjOT0 dJs@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.Susp endLayout()
        For n = 1 To 20
        LineStr = Space(16)
        >
        Mid(LineStr, 1, 10) = PriceData(n).It emID
        Mid(LineStr, 13, 4) = PriceData(n).It emPrice
        >
        listPrices.Item s(n - 1) = LineStr 'the fault is probably
        here
        Next n
        listPrices.Resu meLayout()
        >
        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?

        Comment

        Working...