Solved

Control Flickering (Listview)

Posted on 2003-11-17
11
551 Views
Last Modified: 2008-03-17
Hello, How can I have a simple listview control that updates every 2 seconds not flicker?

Recently i posted this question: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20774715.html

OK, now im testing it and am noticing that it does an ok job, but still shows flickering and is anoying.

My test and example: Please download http://www.clear100.com/experts-exchange/listview_refresh/modListView_Colorize.zip

If you can download that there is also a little added bonus in it, it showes a sample of the flickering and i wanted to know if you can help me figure it out, and also it shows somthing else really cool with the list contorl, check it out and be supprised...
:D

Let me know as soon as you can please?

Bill.

Old Question: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20774715.html
0
Comment
Question by:clear100-com
  • 6
  • 5
11 Comments
 

Expert Comment

by:Gryff
ID: 9763108
Well if you are updateing the screen that many columns that often then flickering is going to be hard to avoid, you can lessen it by only changing the bits that have changed and avoiding clearing it and recreateing it all the time. If you example if you move a the creation bit to the start button ie...

    Dim I As Integer
    For I = 1 To 30
        ListView1.ListItems.Add I, , , , 1
        ListView1.ListItems(I).SubItems(1) = Timer
        ListView1.ListItems(I).SubItems(2) = Date
        ListView1.ListItems(I).SubItems(3) = Time
    Next I
    Timer1.Enabled = True
    Timer1.Interval = Val(Trim(Text1.Text))
End Sub

Which is basically just initialising the listview, then in the timer have something similar to ...

Private Sub Timer1_Timer()
    'LockWindowUpdate Me.hwnd
    'ListView1.ListItems.Clear
    Dim I As Integer
    For I = 1 To 30
        ListView1.ListItems(I).SubItems(1) = Timer
        If ListView1.ListItems(I).SubItems(2) <> Date Then ListView1.ListItems(I).SubItems(2) = Date
        If ListView1.ListItems(I).SubItems(3) <> Time Then ListView1.ListItems(I).SubItems(3) = Time
    Next I
    'LockWindowUpdate False
End Sub

In this example (least on my machine) the lockwindowupdate does little to remove the flickering, but if you are making large changes in bursts then I guess it would help more.

Basically avoid rewriting anything that doesn't need to be rewritten and you will avoid alot of flickering. I know this won't eliminate everything in your example, bt hopefully it will help.
0
 

Author Comment

by:clear100-com
ID: 9763595
OK, thanks, but still going to keep this open for more input.
0
 

Author Comment

by:clear100-com
ID: 9763947
The problem is, the app that im using this on i never know what the sze of the list is going to be, so in my case i just need to clear the list and refresh, i suppose i can re-write the code like you suggest wich may not be a bad thing at all, however i just want other ides if any exist (my doubts thogh that any more exist)

Bill.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Expert Comment

by:Gryff
ID: 9763987
Can you not add and remove the additional entries as you get them?

If you are pulling them from a database is there a unique field (primary or foriegn key) that you can place in the key field of the listview which will allow you to check for new entries?

If you clear and rebuild the list every time it will be almost impossible to avoid the flickering, at least in my experience so far.
0
 

Author Comment

by:clear100-com
ID: 9764091
Not really, it will be hard to do this because as i get the info from the db i need to update the list acording to how the user has it sorted.
0
 

Accepted Solution

by:
Gryff earned 35 total points
ID: 9764361
Possibly I am not understanding the way you are doing this, but the key, Unlike the index, is irrelevent of the sort order. So, for example, if you have a table like so...
ClientID     ClientName      Address
1               John Jones       London, England
2               Adam Smith     Farnborough, England
3               Joe Bloggs       Arkansaw, USA

You would populate your listview in this manner,

ListView1.ListItems.Add I, rs!ClientId, rs!ClientName, , 1
ListView1.ListItems(I).SubItems(1) = rs!Address

Which would give you your Name and address Columns while maintaing a unique key for each item. If the table gained a new entry you would just either search for an Listitem which a key the same as the ClientID and if it is not their insert it, or failing that you could try to add it and trap for the error that occurs for a non-unique key.

Equally for removing items if you had items in your listview that there is no corrosponding ClientID then you can use the remove method to delete them without rebuilding the entire listview.

In addition to reducing flicker it will enhance your programs performance.


0
 

Author Comment

by:clear100-com
ID: 9765078
Thank you, im sorry i don't have more points, its really nice of you to help.
0
 

Expert Comment

by:Gryff
ID: 9765115
Not a problem, I participate here to increase my skills and knowledge not to get a high score :-D
0
 

Author Comment

by:clear100-com
ID: 9765419
Ok, can you change the icons every other time (or on a random time) and see if it flickers?  It is doing it for one of my apps.
0
 

Expert Comment

by:Gryff
ID: 9770224
Hmm, yep, noticable flicker when changing lots of icons, looks like it is rebuilding the entire line when the icon is changed.
Not been able to reduce it my end though. How often are you changing the icons?
0
 

Author Comment

by:clear100-com
ID: 9772092
every second
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

809 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