Solved

ListView Filicker

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

623 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