Click to See Complete Forum and Search --> : ListView updating


Rippin
January 16th, 2000, 01:51 AM
I have a rather large recordset that I display in a listview. How do you turn off the updating (or redraw) property for the listview via API?

Thanks

Chris Eastwood
January 17th, 2000, 02:56 AM
You can use the SendMessage API with the WM_SETREDRAW message on most controls :

Here's an example I use to clear down a treeview with 100's of nodes - it's far quicker than the standard nodes.clear method, and it uses the WM_SETREDRAW message to make it even faster :



'
' Constants / Declarations - Change public / private as required
'
public Const TV_FIRST as Long = &H1100
public Const TVM_GETNEXTITEM as Long = (TV_FIRST + 10)
public Const TVM_DELETEITEM as Long = (TV_FIRST + 1)
public Const TVGN_ROOT as Long = &H0
public Const WM_SETREDRAW as Long = &HB
'
public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
(byval hwnd as Long, byval msg as Long, byval wParam as Long, _
byval lParam as Long) as Long
'
' Very fast Clearing of treeview control - Place this where required
'
private Sub ClearTreeView(byval tvHwnd as Long)
'
Dim lNodeHandle as Long
'
' Turn off redrawing on the Treeview for more speed improvements
'
SendMessageLong tvHwnd, WM_SETREDRAW, false, 0
'
Do
lNodeHandle = SendMessageLong (tvHwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0)
If lNodeHandle > 0 then
SendMessageLong tvHwnd, TVM_DELETEITEM, 0, lNodeHandle
else
Exit Do
End If
Loop
'
' Turn Drawing back on ...
'
SendMessageLong tvHwnd, WM_SETREDRAW, true, 0
End Sub




Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Lothar Haensler
January 17th, 2000, 03:54 AM
some people say that LockWindowUpdate is even faster and easier to call.


private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (byval hwndLock as Long) as Long
LockWindowUpdate yourcontrol.hWnd
' if you want to update again...
LockWindowUpdate 0

Chris Eastwood
January 17th, 2000, 03:56 AM
I agree - most people say use LockWindowUpdate, but when ever I've tried to use it (when 'unlocking') - the whole desktop tends to flicker and get redrawn - (which looks really ugly). I tend to use the WM_SETREDRAW method now in a wrapped routine just like LockWindowUpdate.

Any ideas on how to get rid of the flickering.... ?


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Lothar Haensler
January 17th, 2000, 04:00 AM
I have just tried it and couldn't see any flickering or desktop redraw operation.
I use NT 4 and VB 6.

Chris Eastwood
January 17th, 2000, 04:06 AM
I've found that it's one of those 'sometimes it does/doesn't' problems. I've had it working fine before on NT4 with VB5/6 and yet the same code on a different machine would do the 'flicker'. It tend's more noticable on a Win98 machine.

I'm wondering if it's the value placed into LockWindowUpdate to release the 'lock' - I usually call it as :

LockWindowUpdate 0&

- But surely this is going to refer to the desktop window ? (Although that doesn't explain the inconsistancies between machines/OS).



Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Lothar Haensler
January 17th, 2000, 04:12 AM
>LockWindowUpdate 0&
>
>- But surely this is going to refer to the >desktop window ?

I tend to disagree. Since only ONE window can be locked at a time, IMHO passing 0 to Lockwindowupdate simply means: unlock the window that was locked most recently. Redrawing the desktop in that case simply doesn't make sense to me.
I haven't had the chance to test that stuff on different machines or OSs, yet.

Rippin
January 17th, 2000, 03:28 PM
Thanks guys..both ways seem to do pretty well. Thanks a bunch!!!

Bruno
January 17th, 2000, 03:41 PM
>both ways seem to do pretty well.
Last time I checked this didn't work. ListView was ignoring messages. Are you sure you tested it?

Rippin
January 17th, 2000, 03:51 PM
I don't know. I used Spy++ to display messages for the ListView, and when my code ran it said that it was receiving the WM_SETREDRAW messages, but that doesn't mean it actually did anything. Plus, it still flickered a little bit, but that might be because I am resizing the columnheaders after displaying the data.

Bruno
January 17th, 2000, 05:24 PM
You should send message to parent form:

'Declarations
private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (byval hWnd as Long, byval wMsg as Long, _
byval wParam as Long, lParam as Long) as Long
private Const WM_SETREDRAW = &HB
private Const REDRAWOFF as Long = 0
private Const REDRAWON as Long = 1

'Use this in your procedure:
' disable repainting
Call SendMessage(hWnd, WM_SETREDRAW, REDRAWOFF, 0&)
' now modify your listview
...
' enable repainting
Call SendMessage(hWnd, WM_SETREDRAW, REDRAWON, 0&)



--------------------------------------
After setting redrawon, you can use:
1. ListView.Refresh
2. Nothing, since next line will do refresh (e.g. setting Sorted property)
3. best ***
I am using sometimes:
private Declare Sub InvalidateRect Lib "user32" _
(byval hWnd as Long, byval t as Long, byval bErase as Long)
Call InvalidateRect(Listview1.hWnd, 0&, 0&)
' and my forms.ClipControls is set to false

Bruno
January 17th, 2000, 05:41 PM
>passing 0 to Lockwindowupdate simply means: unlock the window that was locked most recently
There are 2 cases (tested on Win95):


'1. desktop will be repainted
' disable repainting
LockWindowUpdate hwnd
' resize our form
Move Left, Top, Width + 30, Height + 30
' do some processing (e.g. dinamically add some controls)
'
' this will refresh DESKTOP
LockWindowUpdate 0

'2. only form
' resize form before LockWindowUpdate call
Move Left, Top, Width + 30, Height + 30
Refresh
' disable repainting
LockWindowUpdate hwnd
' do some processing (e.g. dinamically add some controls)
'
' this will refresh only current form
LockWindowUpdate 0

Chris Eastwood
January 18th, 2000, 03:57 AM
Thanks Bruno - I'll take a look and see if I'm doing something similar (I expect so)


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb