Solved

Control Flickering (Listview)

Posted on 2003-11-17
11
552 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 65
How to make an ADE file by code? 11 94
VBA to find and replace multiline text from VBA modules 8 64
VBA: loop recent folder and copy txt file. 8 33
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

856 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