flickering listview

J

jtalbot_vizible

I was looking at the code on codeproject to solve my listview
flickering issue. All the references to functions in the rest of my
post refer to that code. It's available at
http://www.codeproject.com/cs/miscc...=100&forumid=14314&select=1488858&msg=1488858

That code didn't solve my problem. I have a ListView (in Details mode)
with about 70 rows and 12 columns. It's a stock ticker kind of app.
When it first starts, each subitems are updated once as data is
received from the server. During that time flickering is so bad, it's
probably epilepsy seisure-inducing. The update messages are coming from
a library at random intervals.

After the initial global update, individual subitems are updated fairly
frequently -- I'd say about 20 subitems per second. The updating for
each subitem includes font color changes, background color changes, and
subitem text changes (no rows/columns are added or removed). Even
during those updates it's still pretty obvious that the background is
being repainted -- it still flickers.

Stepping through the code, it seems like the call to this.Update() in
the function updateItem() returns right away. By the time the WndProc
function gets called, updateItem() has already re-setted the updating
flag to false.

To test out that theory, I commented the line in UpdateItem() that sets
updating to false, rather set it to false in the WndProc function, as
follow:

protected override void WndProc(ref Message messg)
{
if (myUpdating)
{
myUpdating = false;
if ((int)WM.WM_ERASEBKGND == messg.Msg)
{
...
}
...
}
...
}

This made no difference whatsoever. (still don't know why)

I then tried ALWAYS cancelling WM_ERASEBKGND messages, and that worked
(well, I got flicker-free updates (it was beautiful I tells ya!), but
of course scrolling, resizing, etc. didn't work properly).

The library I'm using to get the stock market data is multi-threaded. I
came to the conclusion that a different thread calls the updateItem()
function than what calls WndProc(). I didn't think that was possible.
The class that receives the messages from the 3rd party library
implements ISynchronizeInvoke, and the library properly calls
InvokeRequired, etc, which I thought would force all my code to be
called by the same thread. Apparently not.

Anyway, I suppose if I had a synchronous version of Control.Update()
(the function being called in UpdateItem() between setting the update
flag to true and setting it to false) then everything would be cool. Is
there such a thing?

If anybody has any suggestion on how to solve this, pls let me know :)
I suppose extending the codeproject code with a list of items to update
would do it, but I'm hoping there's something simpler that I'm missing.
 
D

_DD

I was looking at the code on codeproject to solve my listview
flickering issue. All the references to functions in the rest of my
post refer to that code. It's available at
http://www.codeproject.com/cs/miscc...=100&forumid=14314&select=1488858&msg=1488858

I was just looking at a GroupBox control on CodeProject today, and it
had some comments about anti-flicker. Dug it up again just in case
it's something you haven't tried. Also, I usually refresh controls on
higher granularity.

Group Box: http://www.codeproject.com/useritems/grouper.asp
 
L

Lee Alexander

I had a similar issue. I derived from ListView and in the constructor set
the property 'DoubleBuffered' to true, then i used the modified class in the
originals place. It seemed to do the trick for me...

Regards
Lee
 
J

jtalbot_vizible

I switched to using a DataGrid instead of a ListView. The window
doesn't flicker at all, and performance appears to be much better too.

However, there is a new issue: when the app window is not in the
foreground (I haven't tried minimizing), the *rest* of the screen
flickers: desktop icons, other applications, etc. <sigh>

Is this a known issue? (a bit of googling didn't yield anything yet).
 

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