Solved

LockWindowUpdate

Posted on 2002-04-09
5
738 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 139
Printing problem 2 80
Error E2158 compiling with Delphi XE10 Seattle 2 83
Tembedded WB animatid gifs not animated on some pcs 2 71
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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