Solved

ListView Filicker

Posted on 1998-10-29
5
757 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

Technology Partners: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

679 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