C # flickering list in update

I have a list that is updated periodically (every 60 seconds). I was unpleasant that I get a flicker every time it becomes obsolete. The method used was to clear all the elements and then recreate them. I decided instead of clearing the elements, which I simply write directly to the cell with new text. This is the best approach or someone has a better solution.

+43
c # listview flicker
Jan 14 '09 at 12:44
source share
11 answers

The ListView control has a flicker problem. The problem is that the control overload of the update is incorrectly implemented so that it acts like Refresh. The update should cause the control to redraw only invalid regions, while Refresh redraws the controls of the entire client area. Therefore, if you must change, say, the background color of one element in the list, then only this specific element needs to be repainted. Unfortunately, the ListView control seems to have a different opinion and wants to recolor its entire surface whenever you are interacting with one item ... even if the item is not currently displayed. So, in any case, you can easily suppress the flicker by folding your own, as follows:

class ListViewNF : System.Windows.Forms.ListView { public ListViewNF() { //Activate double buffering this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); //Enable the OnNotifyMessage event so we get a chance to filter out // Windows messages before they get to the form WndProc this.SetStyle(ControlStyles.EnableNotifyMessage, true); } protected override void OnNotifyMessage(Message m) { //Filter out the WM_ERASEBKGND message if(m.Msg != 0x14) { base.OnNotifyMessage(m); } } } 

From: Geekswithblogs.net

+73
Jan 14 '09 at 12:47
source share
— -

In addition to other answers, many controls have a [Begin|End]Update() method that can be used to reduce flickering when editing content - for example:

  listView.BeginUpdate(); try { // listView.Items... (lots of editing) } finally { listView.EndUpdate(); } 
+21
Jan 14 '09 at 12:54
source share
+4
Jan 14 '09 at 12:48
source share

Excellent question and answer by Storm. Here C ++ is the port of its code for anyone who can implement C ++ / CLI.

 #pragma once #include "Windows.h" // For WM_ERASEBKGND using namespace System; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class FlickerFreeListView : public ListView { public: FlickerFreeListView() { //Activate double buffering SetStyle(ControlStyles::OptimizedDoubleBuffer | ControlStyles::AllPaintingInWmPaint, true); //Enable the OnNotifyMessage event so we get a chance to filter out // Windows messages before they get to the form WndProc SetStyle(ControlStyles::EnableNotifyMessage, true); } protected: virtual void OnNotifyMessage(Message m) override { //Filter out the WM_ERASEBKGND message if(m.Msg != WM_ERASEBKGND) { ListView::OnNotifyMessage(m); } } }; 
+4
Jul 15 2018-10-15
source share

If this can help, the following component solved my ListView flashing errors with .NET 3.5

 [ToolboxItem(true)] [ToolboxBitmap(typeof(ListView))] public class ListViewDoubleBuffered : ListView { public ListViewDoubleBuffered() { this.DoubleBuffered = true; } } 

I use it in conjunction with the .BeginUpdate () and .EndUpdate () methods, where I do ListView.Items manipulations.

I do not understand why this property is protected ... even in .NET 4.5 (perhaps a security issue)

+3
Dec 17 '12 at 12:20
source share

The simplest solution is probably to use

  listView.Items.AddRange(listViewItems.ToArray()); 

instead

  foreach (ListViewItem listViewItem in listViewItems) { listView.Items.Add(listViewItem); } 

It works better.

+2
May 08 '15 at 18:22
source share

A simple solution

 yourlistview.BeginUpdate() //Do your update of adding and removing item from the list yourlistview.EndUpdate() 
+1
Aug 20 '14 at 10:06
source share

Try setting the double buffering property to true.

Also you can use:

 this.SuspendLayout(); //update control this.ResumeLayout(False); this.PerformLayout(); 
0
Jan 14 '09 at 12:53
source share

I know this is a very old question and answer. However, this is the best result when searching for "C ++ / cli listview flicker" - even though it doesn't even talk about C ++. So here is the C ++ version:

I put this in the header file for my main form, you can put it in another place ...

 static void DoubleBuffer(Control^ control, bool enable) { System::Reflection::PropertyInfo^ info = control->GetType()-> GetProperty("DoubleBuffered", System::Reflection::BindingFlags::Instance | System::Reflection::BindingFlags::NonPublic); info->SetValue(control, enable, nullptr); } 

If you are lucky enough to land here to find a similar answer for managed C ++, this works for me. :)

0
Oct 27 '16 at 19:42
source share

In Winrt Windows phone 8.1, you can install the following code to fix this problem.

 <ListView.ItemContainerTransitions> <TransitionCollection/> </ListView.ItemContainerTransitions> 
0
Nov 28 '16 at 5:41
source share

Here is my quick fix for a C # implementation that does not require subclassing list views, etc.

Uses reflection to set the DoubleBuffered property to try in the form designer.

  lvMessages .GetType() .GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .SetValue(lvMessages, true, null); 
0
Feb 22 '17 at 11:10
source share



All Articles