Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ListView Filicker

Posted on 1998-10-29
5
Medium Priority
?
767 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Industry Leaders: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

715 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