Go Premium for a chance to win a PS4. Enter to Win

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

LockWindowUpdate

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
Stuart_Johnson
Asked:
Stuart_Johnson
  • 2
  • 2
1 Solution
 
kretzschmarCommented:
why not use

begin
  DataListView.Items.BeginUpdate;
  try
    {code}
  finally
    DataListView.Items.EndUpdate;
  end;
end;
0
 
intheCommented:
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
 
Stuart_JohnsonAuthor Commented:
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
 
intheCommented:
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
 
Stuart_JohnsonAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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