[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1372
  • Last Modified:

Avoid flicker when updating TListView

I have a TListView with a small number of items that I however need to update a couple of times every second. When I'm doing this I get an annoying flicker. This disappears if I set DoubleBuffering to true but then everyting seems to be slowed down instead. For example, moving the window or selecting rows feels like walking around in glue... :-/ Anyone know of a way to avoid flickering without slowing down the application? Thanks!
0
jonassondaniel
Asked:
jonassondaniel
  • 4
  • 4
  • 2
  • +1
1 Solution
 
kretzschmarCommented:
listview1.items.beginUpdate;
try
  //do your update
finally
  listview1.items.endUpdate;
end;

meikl ;-)

0
 
jonassondanielAuthor Commented:
I'm updating a couple of times every second.
0
 
jonassondanielAuthor Commented:
I'm updating a couple of times every second.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
kretzschmarCommented:
doesn't matter,
it will speed up
your update mostly flickree

from the delphi help

Prevents updating of the list view until the EndUpdate method is called.

procedure BeginUpdate;

Description

Call BeginUpdate before making multiple changes to the list of items. When all changes are complete, call EndUpdate so that the changes can be reflected on screen. BeginUpdate and EndUpdate prevent excessive redraws and speed processing time when new items are added, deleted, or inserted.

meikl ;-)
0
 
jonassondanielAuthor Commented:
Before posting things like this you might want to try it or at least make sure what you're talking about...
0
 
kretzschmarCommented:
Before posting comments like this above, you might want to try to show/explain better your needs ...

(i know, what i'm talking about)
0
 
intheCommented:
>>Before posting things like this you might want to try it or at least make sure what you're talking about...

bit rude ..


i agree with meikl,the problem is your updating continuly a couple of times per second doinjg mouse selections on it.doublebuffered uses quite a bit more memory and processing power so it will slow the listview down a bit.

maybe you should use a virtual control instead like mike virtual treeview(can act same as listview):

http://www.lischke-online.de/VirtualTreeview.html

0
 
intheCommented:
only other idea lock the window from painting till you want it to paint(from teamb):

LockControl(listview1.parent,True);
  try
    // do your thing
  finally
    LockControl(listview1.parent,False);
  end;


  procedure LockControl(c: TWinControl; lock: boolean);
  begin
    if (c=nil) or (c.Handle=0) then exit;

    if lock then SendMessage(c.Handle,WM_SETREDRAW,0,0)
    else begin
      SendMessage(c.Handle,WM_SETREDRAW,1,0);
      RedrawWindow(c.Handle,nil,0,
        RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
    end;
  end;
 
0
 
Lee_NoverCommented:
updating a listview more than once a second is kinda um .. stoopid ?
if you really gotta do it then use DoubleBuffered
but as it was already said it uses twice the memory and is a bit slower :)
and BeginUpdate EndUpdate helps a lot if you update more than one item

using DoubleBuffered:=true and Begin/EndUpdate will get you the best visual experience with TListView

lischkes VirtualTreeView is also one great piece of a component :)
but you have to write lots of stuff yourself
0
 
jonassondanielAuthor Commented:
The Virtual Treeview component was gold! Thanks!

And sorry for my previous grumpy comment... It was the consequence of hours of ListView fiddling ;-)
0
 
kretzschmarCommented:
>sorry for my previous grumpy comment
is ok
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now