0
public ListViewNF(IContainer container)
{
    container.Add(this);

    InitializeComponent();

    //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's 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);
    }
}

In the Load event:

private void Form1_Load(object sender, EventArgs e)
{
    ListViewNF nf = new ListViewNF();
}

I'm getting error on the line inside the ListViewNF:

InitializeComponent();

Severity Code Description Project File Line Suppression State Error CS0120 An object reference is required for the non-static field, method, or property 'Form1.InitializeComponent()'

I tried to remove this line to avoid errors but it didn't fix the flickering. I also tried adding listView1, beginupdate and endupdate:

listView1.BeginUpdate();
foreach (ListViewItem li in listView1.Items)
{
    if (li.SubItems[2].Text == lastUrl)
    {
        li.SubItems[0].Text = "Downloaded";
        li.SubItems.Add("Color");
        li.SubItems[0].ForeColor = Color.Green;
        li.UseItemStyleForSubItems = false;
    }
}
listView1.EndUpdate();

I tried this before adding the ListViewNF method. So far nothing helped with the flickering. Any suggestions?

Chris Hamilton
  • 555
  • 5
  • 22
Daniel Halfoni
  • 487
  • 10
  • 30
  • What is the LoC that is not instantiated? (Tip: temporarily remove the Debuggable attribute from the InitializeComponent method to find out). Flickering tends to point to *double buffering*, Google it and confirm that's not the problem – Jeremy Thompson Mar 14 '17 at 10:41
  • Keep parameterless form constructor untouched (where it calls `InitializeComponent()`) and add new constructor like this `public ListViewNF(IContainer container): base() { ... your code ... }`. – Sinatr Mar 14 '17 at 10:41
  • @Sinatr he has the overloaded constructor, good spot, he/she isn't passing the container variable to it. – Jeremy Thompson Mar 14 '17 at 10:50
  • @Sinatr i'm using now the answer accepted in the link you provided in your second comment, and it's working fine. I also added beginupdate and endupdate. I just wonder in this link you provided i read some other comments there and they are against this solution like the answer with the 46 votes there. I just wonder why they are against this solution ? What's wrong with it ? – Daniel Halfoni Mar 14 '17 at 10:58

0 Answers0