title: Clearing ListView items create duplicate items when using events
body: <p>I have a list view that I want to be able to clear from items and then fill it up again.<br />
  I need to use it with events to my <code>Engine</code> class.</p>
  <p>The problem starts when I clear the items and run it again, it duplicate my items:<br />
  <a href="https://i.stack.imgur.com/PHgHC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PHgHC.png" alt="enter image description here" /></a></p>
  <p>Any idea why it happens and how to solve it?<br />
  Clearing the list view or initialize new list view doesn't work for me.</p>
  <p>My Form code:</p>
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Windows.Forms;
  
  namespace WindowsFormsApp3
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private delegate void createListViewCallBack(string i_File, string i_FileStatus);
          private void createListView(string i_File, string i_FileStatus)
          {
  
              if (this.InvokeRequired)
              {
                  createListViewCallBack s = new createListViewCallBack(createListView);
                  this.Invoke(s, i_File, i_FileStatus);
              }
              else
              {
                  ListViewItem item = new ListViewItem(i_File);
                  item.SubItems.Add(i_FileStatus);
                  listView1.Items.Add(item);
              }
          }
  
  
          private void buttonStart_Click(object sender, EventArgs e)
          {
              Engine.BuildListViewUpdate += Engine_BuildListViewUpdate;
              Engine.BuildList();
              //createListView(@&quot;c:\a.txt&quot;, @&quot;yes&quot;);
              //createListView(@&quot;c:\b.txt&quot;, @&quot;no&quot;);
          }
  
  
          private delegate void buildListUpdateCallBack(string i_File, string i_FileStatus);
          private void Engine_BuildListViewUpdate(string i_File, string i_FileStatus)
          {
              if (this.InvokeRequired)
              {
                  buildListUpdateCallBack s = new buildListUpdateCallBack(Engine_BuildListViewUpdate);
                  this.Invoke(s, i_File, i_FileStatus);
              }
              else
              {
                  ListViewItem item = new ListViewItem(i_File);
                  item.SubItems.Add(i_FileStatus);
                  listView1.Items.Add(item);
              }
          }
  
          private void clear1()
          {
              this.listView1 = new ListView();
              //this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
              //this.columnHeader1,
              //this.columnHeader2});
              this.listView1.HideSelection = false;
              this.listView1.Location = new System.Drawing.Point(55, 156);
              this.listView1.Name = &quot;listView1&quot;;
              this.listView1.Size = new System.Drawing.Size(633, 265);
              this.listView1.TabIndex = 1;
              this.listView1.UseCompatibleStateImageBehavior = false;
              this.listView1.View = System.Windows.Forms.View.Details;
          }
  
          private void buttonClear_Click(object sender, EventArgs e)
          {
              listView1.Items.Clear();
              //listView1.Clear();
              //clear1();
          }
      }
  }
  
  
  </code></pre>
  <p>My Engine class:</p>
  <pre class="lang-cs prettyprint-override"><code>
  namespace WindowsFormsApp3
  {
      public delegate void BuildListViewEventHandler(string i_File, string i_FileStatus);
      static class Engine
      {
          public static event BuildListViewEventHandler BuildListViewUpdate;
  
          public static void BuildList()
          {
              BuildListViewUpdate(@&quot;c:\a.txt&quot;, @&quot;yes&quot;);
              BuildListViewUpdate(@&quot;c:\b.txt&quot;, @&quot;no&quot;);
          }
  
          public static void OnBuildListViewUpdate(string i_File, string i_FileStatus)
          {
              if (BuildListViewUpdate != null)
              {
                  BuildListViewUpdate.Invoke(i_File, i_FileStatus);
              }
          }
      }
  }
  
  
  </code></pre>