|
-
Jun 1st, 2005, 05:51 AM
#1
Thread Starter
New Member
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
-
Jun 1st, 2005, 07:14 AM
#2
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.
-
Jun 1st, 2005, 10:19 AM
#3
Thread Starter
New Member
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
-
Jun 1st, 2005, 10:48 AM
#4
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/
-
Jun 1st, 2005, 11:37 AM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 1st, 2005, 01:04 PM
#6
Re: Flicker Free Listview - VB.NET
 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.
-
Jun 1st, 2005, 01:06 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 1st, 2005, 01:29 PM
#8
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.
-
Jun 1st, 2005, 02:28 PM
#9
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.
-
Jun 1st, 2005, 11:08 PM
#10
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!!
-
Jun 2nd, 2005, 04:49 AM
#11
Frenzied Member
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
and add thousand of items and nodes then after the loop finishes
make it repaint all once
like this
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.
-
Jun 2nd, 2005, 04:55 AM
#12
Frenzied Member
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
-
Jun 2nd, 2005, 05:30 AM
#13
Thread Starter
New Member
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:
Delegate Sub AddToLstvDelegate(ByVal lstvListView As ListView, ByVal AddItem As String, ByVal ImageNumber As Integer, ByVal Color As Integer)
Public Sub AddToLstv(ByVal lstvListView As ListView, ByVal AddItem As String, ByVal ImageNumber As Integer, ByVal Color As Integer)
Dim listViewItem As New ListViewItem
listViewItem.Text = AddItem
listViewItem.ForeColor = gcolColors(Color)
listViewItem.ImageIndex = ImageNumber
lstvListView.Items.Add(listViewItem)
Dim r As Rectangle = lstvListView.GetItemRect(0)
Dim nVisibleItems As Integer = lstvListView.Height \ r.Height
If lstvListView.TopItem.Index + nVisibleItems >= lstvListView.Items.Count - 1 Then
lstvListView.EnsureVisible(lstvListView.Items.Count - 1)
End If
End Sub
'Filling a listview
mess = m_sMes.Split(seperator)
If m_strFTP = "SOURCE" And m_intWindowNum > -1 Then
For intTeller = 0 To mess.Length - 2
gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog.Invoke( _
New frmMain.AddToLstvDelegate( _
AddressOf frmMain.AddToLstv), New Object() _
{gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog, "[L] " & mess(intTeller), 1, 82})
Next intTeller
End If
If m_strFTP = "DESTINATION" And m_intWindowNum > -1 Then
For intTeller = 0 To mess.Length - 2
gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog.Invoke( _
New frmMain.AddToLstvDelegate( _
AddressOf frmMain.AddToLstv), New Object() _
{gstrcFXPWindows(m_intWindowNum).lstvFXPWindowLog, "[R] " & mess(intTeller), Nothing, 79})
Next intTeller
End If
Hope anybody has a suggestion!
Greetz
djrud
-
Jun 2nd, 2005, 01:58 PM
#14
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
-
Jun 15th, 2005, 07:23 AM
#15
Thread Starter
New Member
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
-
Jun 15th, 2005, 08:13 AM
#16
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
-
Jul 28th, 2009, 09:56 AM
#17
New Member
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.
-
Jul 28th, 2009, 10:52 AM
#18
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.
-
Jul 28th, 2009, 08:39 PM
#19
New Member
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.
-
Nov 11th, 2009, 04:02 AM
#20
Lively Member
Re: Flicker Free Listview - VB.NET
 Originally Posted by Bill_Logan
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()
-
Nov 11th, 2009, 04:25 AM
#21
Lively Member
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
-
Jan 25th, 2011, 12:20 PM
#22
Member
Re: Flicker Free Listview - VB.NET
 Originally Posted by maged
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
and add thousand of items and nodes then after the loop finishes
make it repaint all once
like this
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|