Solved

LockWindowUpdate

Posted on 2002-04-09
5
737 Views
Last Modified: 2010-05-18
Hi,

I'm updating a ListView which contains about 150 items.  The update requires me to completely repopulate the entire ListView.  The problem is, it takes ages and looks disgusting when the items are deleted and re-added.  I've played around with LockWindowUpdate, and that works fine with the ListView, but my desktop refreshes when I release the lock.

Here's my code:

begin
  LockWindowUpdate(DataListView.Handle);
  {code}
  LockWindowUpdate(0);
end;

Is this correct?  If so, why does the desktop refresh?

This has happened to me on 98SE, 2000 and XP.  I haven't tried it on any other versions of Windows.

Cheers,

Stu
0
Comment
Question by:Stuart_Johnson
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 6930447
why not use

begin
  DataListView.Items.BeginUpdate;
  try
    {code}
  finally
    DataListView.Items.EndUpdate;
  end;
end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 6930530
hi stu,
this is a "bug" since d2 ,seems to be with most delphi twincontrols ,you can do as meikl suggested or put a panel under the listview and call lockcontrol on the panel
(suggested by TeamB) :

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;


LockControl(panel1,true);
//do stuff
LockControl(panel1,false);
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 6930572
Hi Barry,

LOL!  3 versions later and it's still not working.  Let me guess, it's knackered in v6 as well?

Thanks for the code.  Which one would either/both of you suggest I use?  Meikl's suggestion works fine, but if yours is the more "accepted" way of doing it, then I'd prefer to go that way.

Cheers,

Stu
0
 
LVL 17

Expert Comment

by:inthe
ID: 6930597
yeh it must be something quite deep in the source tree otherwise it would be fixed ,the earliest mention of the problem i found was 1996!

anyway, i would use beginupdate/endupdate.
lockwindowupdate or lockcontrol is a bit of an overkill really for this ;-).

Regards Barry
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 6930949
No worries, Barry.  However, I'll put that code into CodeBank for later use :)

Thanks for the help, Meikl.  It worked well.

Stu
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now