Solved

ListView Filicker

Posted on 1998-10-29
5
753 Views
Last Modified: 2013-12-26
Hi,

I have a ListView, often when I add a row to the view
(theListView.ListItems.add ...) the whole listview seems to be redrawn (Column headers and all!).  The end result is that it looks really bad as there is so much redrawing and flickering going on.  The sorted property is not enabled.

Any Ideas?  Is this supposed to happen?

Thanks,

Kevin
0
Comment
Question by:KevinG
5 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1488020
Do you use the refresh command or send the ListView_RedrawItems message?
0
 

Author Comment

by:KevinG
ID: 1488021
Hi,

I am simply calling :

    Set itm = theFailView.ListItems.Add(, , location, 1, 1)

Every time this is called the whole listview is beign redrawed (including the ColumnHeaders).

Bye,

Kevin
0
 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
ID: 1488022
'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 LoadListViev procedure:
    ' disable repainting
    Call SendMessage(hWnd, WM_SETREDRAW, REDRAWOFF, 0&)
    ' now add items to your listview
    ...
    ' enable repainting
    Call SendMessage(hWnd, WM_SETREDRAW, REDRAWON, 0&)
' Point-back guaranty:
' If this flickers, I guaranty return of your points
0
 
LVL 15

Expert Comment

by:ameba
ID: 1488023
But, this is not all.
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(Ctl.hWnd, 0&, 0&)
' and my forms.ClipControls is set to False

0
 

Expert Comment

by:geonas
ID: 1488024
You can also use the LockWindowUpdate API as following:

1- Add the following declaration:

#If Win16 Then
    Declare Function LockWindowUpdate Lib _
        "User" (ByVal hWndLock As Integer) As Integer
#Else
    Declare Function LockWindowUpdate Lib _
        "user32" (ByVal hWndLock As Long) As Long
#End if

2- The hWndLock variable refers to the hWnd property of the form where you don't want to have screen updates shown. When you reissue the LockWindowUpdate with a value of 0 for hWndLock, you'll free up the screen and all updates will be shown instantly:

Dim lErr As Long
Dim x as Integer

'No ListView flicker, it will appear blank for
'just a moment...
Screen.MousePointer = vbHourglass
lErr = LockWindowUpdate(Me.hWnd)

For x=1 to 5000
    Set itm = theFailView.ListItems.Add(, , location, 1, 1)
    'Do whatever with itm
Next

'Now all the information is there
lErr = LockWindowUpdate(0)
Screen.MousePointer = vbDefault

Hope this will answer your question,

Regards
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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

912 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

21 Experts available now in Live!

Get 1:1 Help Now