Results 1 to 22 of 22

Thread: Flicker Free Listview - VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    15

    Post Flicker Free Listview - VB.NET

    Hi,

    I'm using a listview control as a log window for a self-made FTP client application.
    Sometimes I need to add a row at slow speeds, but also sometimes a lot of information (50-100 rows, like dirlistings, login messages of FTP servers) has to be added to the listview within a For/Next loop.

    Now adding rows very quickly makes the listview flicker in an ennoying way. So much, the listview is hardly to read.
    For me, it is important I can see every row added (using different colors to know different meanings).

    Searching the internet, I find solutions using BeginUpdate & Endupdate of the listview control just outside the bounds of the For/Next loop. This makes that the new rows are displayed only when the For/Next loop is complete.

    For me, that is no solution, because I have to see every row that is added very quickly (remeber the different colors I use).

    Does anyone know a solution to significant reduce the flickering (maybe without using BeginUpdate & EndUpdate?), but where I still can see every single row added?

    (Solutions must exist, because commercial FTP clients don't have that flickering in their log windews)

    A solution using VB.NET or API would be most welcome (but a solution in another language like C++ or C# is also welcome).

    If possible, please add a code sample, then just pointing to some method, because It will be a lot easier for me to implement then!

    Thx very much!
    djrud

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Flicker Free Listview - VB.NET

    You might have to modify the drawing routines of the listbox (I have no sample code though) or even create a new control that does what you want.
    I don't live here any more.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    15

    Re: Flicker Free Listview - VB.NET

    I really don't know how to modify the drawing of the listview, like you suggested.

    Anybody got a clue or another suggestion?

    Greetz
    djrud

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Flicker Free Listview - VB.NET

    i never really noticed any flickering in the listview in my apps... can you maybe show some of your code you use when filling the listview/

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flicker Free Listview - VB.NET

    How about the .AddRange method? Dont know if it will show the progress exactly as you want but its supposed to be used for adding
    allot of items. Better performance though. How many columns in your listview?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Flicker Free Listview - VB.NET

    Quote Originally Posted by RobDog888
    How about the .AddRange method? Dont know if it will show the progress exactly as you want but its supposed to be used for adding
    allot of items. Better performance though. How many columns in your listview?
    I find both adding in a for next loop or using addrange has pretty much the same effect. My guess is that when using addrange it is infact looping the array you pass to it just as if you did a for next to add them 1 by 1. It does it behind the scenes.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flicker Free Listview - VB.NET

    Yes, but I read that it was the method of choice when adding multiple items and when performance was an issue.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Flicker Free Listview - VB.NET

    well the only time i see any major performance increase is when an Application.DoEvents has been added to the For Next loop when adding listitems... without the DoEvents they are roughly the same in speed. With it though, the loop nearly doubles in time taken.

  9. #9
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Flicker Free Listview - VB.NET

    I concur. This was an issue during the Primes Contest. Did I mention I won that?
    I don't live here any more.

  10. #10
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Flicker Free Listview - VB.NET

    hahah this is funny I was browsing codeproject and saw an article with virtually the same title as your post: here you go
    http://www.codeproject.com/cs/miscctrl/listviewxp.asp

    edit: that appears to be a very ugly example
    Last edited by MrPolite; Jun 1st, 2005 at 11:15 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  11. #11
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Flicker Free Listview - VB.NET

    hi all,

    i think you are missing a simple point, this flickers is caused because every time you add item in the loop the list tree redraws it self.

    so before you must stop the control from redrawing ,like that

    VB Code:
    1. tree1.suspendlayout

    and add thousand of items and nodes then after the loop finishes

    make it repaint all once

    like this

    VB Code:
    1. tree1.resumelayout

    so you can save much of the repainting flickering that is causing you trouble, in the old days of vb6 we used to write Api to suspend and resume controls paint, moreover to use this api , the control must has a handle (HWND) to use it as a passing parameter to Api. But now, with vb.net the life is easier

    just use these two lines and tell me the results

    hope this would help

    RGDS
    Last edited by maged; Jun 2nd, 2005 at 04:53 AM.

  12. #12
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Flicker Free Listview - VB.NET

    by the way,

    this method can be used with nearly all .net controls that have visible appearance.


    i use it when populating comboboxes, listboxes, tree , listviews with thousands of rows and it is so smooth and also fast,

    i will have a performance boost , i am sure of that

    RGDS

  13. #13

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    15

    Re: Flicker Free Listview - VB.NET

    Hi everybody,

    Thanks for all your replies.

    But all the methods you are proposing are based on the same principle:
    1. Stop the listview control repainting
    2. Add all the necessary rows within a for/next loop
    3. redraw the listview control

    But like I said in my question, that is just what I don't want. I want to create a smooth scrolling listview, that displays every row added, with at the least possible flickering, Without the need to blank out or freeze the screen for a few seconds, ...

    The listview is used as a log window for a self-made FTP client, and thus display server replies, login messages, ...

    Here is a code sample that shows the way I add rows to the listview. I'm using a delegate and invoke method to the listview, because the listview is accessed from different threads:

    VB Code:
    1. Delegate Sub AddToLstvDelegate(ByVal lstvListView As ListView, ByVal AddItem As String, ByVal ImageNumber As Integer, ByVal Color As Integer)
    2.  
    3. Public Sub AddToLstv(ByVal lstvListView As ListView, ByVal AddItem As String, ByVal ImageNumber As Integer, ByVal Color As Integer)
    4.  
    5.         Dim listViewItem As New ListViewItem
    6.         listViewItem.Text = AddItem
    7.         listViewItem.ForeColor = gcolColors(Color)
    8.         listViewItem.ImageIndex = ImageNumber
    9.  
    10.         lstvListView.Items.Add(listViewItem)
    11.  
    12.         Dim r As Rectangle = lstvListView.GetItemRect(0)
    13.         Dim nVisibleItems As Integer = lstvListView.Height \ r.Height
    14.         If lstvListView.TopItem.Index + nVisibleItems >= lstvListView.Items.Count - 1 Then
    15.             lstvListView.EnsureVisible(lstvListView.Items.Count - 1)
    16.         End If
    17.  
    18. End Sub
    19.  
    20.  
    21. 'Filling a listview
    22. mess = m_sMes.Split(seperator)
    23. If m_strFTP = "SOURCE" And m_intWindowNum > -1 Then
    24.     For intTeller = 0 To mess.Length - 2
    25.         gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog.Invoke( _
    26.         New frmMain.AddToLstvDelegate( _
    27.         AddressOf frmMain.AddToLstv), New Object() _
    28.         {gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog, "[L] " & mess(intTeller), 1, 82})
    29.     Next intTeller
    30. End If
    31.  
    32. If m_strFTP = "DESTINATION" And m_intWindowNum > -1 Then
    33.     For intTeller = 0 To mess.Length - 2
    34.         gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog.Invoke( _
    35.         New frmMain.AddToLstvDelegate( _
    36.         AddressOf frmMain.AddToLstv), New Object() _
    37.         {gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog, "[R] " & mess(intTeller), Nothing, 79})
    38.     Next intTeller
    39. End If


    Hope anybody has a suggestion!

    Greetz
    djrud

  14. #14
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Flicker Free Listview - VB.NET

    Hi,

    If I can summarise what it sounds like to me, then:

    You want the listview to repaint after every item is added, but you don't want to see the repaint occur.

    You want it to display each item added, which inevitably means scrolling the listbox as it fills up, but you don't want to see the scrolling occur.


    Maybe a partial solution would be to see how many lines there are in the listview and combine the ensurevisible property (or something similar) and the Topitem property as you add items. I'm thinking maybe of a listview that fills from top to bottom, then scrolls so that only the last item added is visible (at the top of the listbox) and then continues filling. You could interrupt this with the beginupdate and endupdate so that it only repaints after the scrolling is complete. I'm not entirely sure that what I've outlined above would do it, but it's a start...

    HTH

    zaza

  15. #15

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    15

    Re: Flicker Free Listview - VB.NET

    Hi,

    Sorry, but none of the solutions suggested creates a smooth scrolling listview even when a lots of a items are added in a short time.

    Most methods are based on stop painting, add your whole rows and then repaint it again. This means a short blank out when lots of rows added. (blanking out is not what I want)
    A smooth scrolling listview means that every row added is seen, but flicker free. I don't say I would then always easy read what is added because of the speed rows are added. But when this would happen flicker-free, it would be a lot of help!

    No one has another solution?

    Sure something must exist, because the commercial FTP clients I use, have log windows which scroll very fast, but they do it flicker-free.

    Greetz,
    djrud

  16. #16
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Flicker Free Listview - VB.NET

    And it wouldn't surprise me to find out that what they use aren't listviews nor a list box.... at least the FTP client I use doesn't use them for the log window.... they use a text box (presumably a RichTextBox as it's got colours and such).

    Does that help any in this case?

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17
    New Member
    Join Date
    Jul 2009
    Posts
    2

    Re: Flicker Free Listview - VB.NET

    Using vb.net, I solved this in a slightly different way. I created a new class called ffListView, which looks like this:

    Code:
    Public Class ffListView
        Inherits ListView
    
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    End Class
    Then I opened the .Designer.vb of my form and changed the initialization of my listview (which is called lvOutput) to the following:

    Code:
            Me.lvOutput = New ffListView
    and that's all I had to do - no flicker of any sort.

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Flicker Free Listview - VB.NET

    I have a feeling this thread was originally based on VS2003/.NET1.1 which had no double buffering options for WinForms.

  19. #19
    New Member
    Join Date
    Jul 2009
    Posts
    2

    Re: Flicker Free Listview - VB.NET

    Probably true... I didn't notice the date :-) I stumbled on this thread while googling a way to fight the dreaded listview flicker. Thought I'd share. I'm not sure why Microsoft doesn't expose the doublebuffer property to an instance of a listview object - having to create a new class inheriting the listview to gain access to it is awkward.

  20. #20
    Lively Member
    Join Date
    Jul 2002
    Posts
    115

    Re: Flicker Free Listview - VB.NET

    Quote Originally Posted by Bill_Logan View Post
    Using vb.net, I solved this in a slightly different way. I created a new class called ffListView, which looks like this:

    Code:
    Public Class ffListView
        Inherits ListView
    
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    End Class
    Then I opened the .Designer.vb of my form and changed the initialization of my listview (which is called lvOutput) to the following:

    Code:
            Me.lvOutput = New ffListView
    and that's all I had to do - no flicker of any sort.

    I did try this ad work fine thanks
    but if I DoubleClick on my listview nothing happened


    Dim F4 As New change
    Me.AddOwnedForm(F4)
    F4.labID.Text = listviewdata.SelectedItems(0).SubItems(0).Text
    F4.ShowDialog()

  21. #21
    Lively Member
    Join Date
    Jul 2002
    Posts
    115

    Re: Flicker Free Listview - VB.NET

    I did copy paste Me.lvOutput = New ffListView
    into form Load when I was reading about this and forgot to remove it

    this work fine know

  22. #22
    Member
    Join Date
    Aug 2009
    Posts
    46

    Re: Flicker Free Listview - VB.NET

    Quote Originally Posted by maged View Post
    hi all,

    i think you are missing a simple point, this flickers is caused because every time you add item in the loop the list tree redraws it self.

    so before you must stop the control from redrawing ,like that

    VB Code:
    1. tree1.suspendlayout

    and add thousand of items and nodes then after the loop finishes

    make it repaint all once

    like this

    VB Code:
    1. tree1.resumelayout

    so you can save much of the repainting flickering that is causing you trouble, in the old days of vb6 we used to write Api to suspend and resume controls paint, moreover to use this api , the control must has a handle (HWND) to use it as a passing parameter to Api. But now, with vb.net the life is easier

    just use these two lines and tell me the results

    hope this would help

    RGDS
    OOOOOH man. Thank you so much! I wrote an app that used a tablelayoutpanel and dynamically added rows to it. each time the rows were added, it did this crazy annoying flicker. the suspend layout/resume layout fixed it!

    Thanks !!!

    Edit: Aww crap just noticed this was like a 2 yr old thread Sorry for the resurrection.
    Last edited by evanrich; Jan 25th, 2011 at 07:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width