Solved

Control Flickering (Listview)

Posted on 2003-11-17
11
549 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
Comment Utility
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
Comment Utility
OK, thanks, but still going to keep this open for more input.
0
 

Author Comment

by:clear100-com
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Accepted Solution

by:
Gryff earned 35 total points
Comment Utility
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
Comment Utility
Thank you, im sorry i don't have more points, its really nice of you to help.
0
 

Expert Comment

by:Gryff
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
every second
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now