Solved

LockWindowUpdate

Posted on 2002-04-09
5
753 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

710 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