Solved

ListView Filicker

Posted on 1998-10-29
5
752 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
Comment Utility
Do you use the refresh command or send the ListView_RedrawItems message?
0
 

Author Comment

by:KevinG
Comment Utility
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
Comment Utility
'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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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