Solved

Control Flickering (Listview)

Posted on 2003-11-17
11
550 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

932 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

18 Experts available now in Live!

Get 1:1 Help Now