Solved

Control Flickering (Listview)

Posted on 2003-11-17
11
554 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

739 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