title: Clear all the items of a listview- c#
body: <p>How can I clear a ListView in C#?</p>
  
  <p>Here's how I populate my ListView:</p>
  
  <pre><code>int listViewCounter = 0;
  for (int i = 0; i &lt; dtXLS.Rows.Count; i++)
  {
      listViewCounter++;
  
      ListViewItem item = new ListViewItem();
      item.Text = "First item" + listViewCounter;
      item.SubItems.Add("sadad" + listViewCounter);
      item.SubItems.Add("sadad" + listViewCounter);
      item.SubItems.Add("sadad" + listViewCounter);
      item.SubItems.Add("sadad" + listViewCounter);
      LV.Items.Add(item);
  
      LV.Items[listViewCounter - 1].SubItems[0].Text = listViewCounter.ToString();
      LV.Items[listViewCounter - 1].SubItems[1].Text = "sample1";
      LV.Items[listViewCounter - 1].SubItems[2].Text = "sample2";
      LV.Items[listViewCounter - 1].SubItems[3].Text = "sample3";
      LV.Items[listViewCounter - 1].SubItems[4].Text = "sample4";
  }
  </code></pre>
  
  <p>The result will be:</p>
  
  <pre><code>1st Column    2nd Column    3rd Column    4th Column    5th Column
  1             sample1       sample2       sample3       sample4
  </code></pre>
  
  <p>Cdeez this is the part of my code so that you can see:</p>
  
  <pre><code>public void ProcessFunction(RichTextBox rtb1, RichTextBox rtb2, DataTable dtXLS, ListView LV)
  {
      int matchlist_counter = 0;
  
  
      string[] wordsToRedact = new string[dtXLS.Rows.Count];
  
  
      for (int i = 0; i &lt; dtXLS.Rows.Count; i++)
      {
          wordsToRedact_counter++;
  
  
          wordsToRedact[i] = dtXLS.Rows[i][0].ToString();
          wordsToRedact[i] = Regex.Escape(dtXLS.Rows[i][0].ToString());
  
  
          Regex test = new Regex(@"\b(" + wordsToRedact[i] + @")\b", RegexOptions.Singleline | RegexOptions.Compiled);
          MatchCollection matchlist = test.Matches(rtb1.Text);
  
  
          if (matchlist.Count &gt; 0)
          {
              for (int j = 0; j &lt; matchlist.Count; j++)
              {
                  WordsToRedact words = new WordsToRedact(matchlist[j]);
  
                  HighLighting HL = new HighLighting();
                  HL.Highlight_Words(pdfRT, words, Color.Yellow);
                  matchlist_counter++;
              }
          }
  
  
  
          ListViewItem item = new ListViewItem();
          item.Text = "First item" + wordsToRedact_counter;
          item.SubItems.Add("sadad" + wordsToRedact_counter);
          item.SubItems.Add("sadad" + wordsToRedact_counter);
  
  
          LV.Items.Add(item);
          LV.Items[wordsToRedact_counter - 1].SubItems[0].Text = wordsToRedact_counter.ToString();
          LV.Items[wordsToRedact_counter - 1].SubItems[1].Text = wordsToRedact[i];
          LV.Items[wordsToRedact_counter - 1].SubItems[2].Text = matchlist_counter.ToString();
  
          matchlist_counter = 0;
      }
  }
  
  
  private void analyzeButton_Click(object sender, EventArgs e)
  {
      listView1.Items.Clear();
      DataTable dtXLS = loadXLS(xls_path);
      WordsToRedactFunc(pdfRT, visfRT, dtXLS, listView1);
      MessageBox.Show("Processing done!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
  }
  </code></pre>
  
  <p>My question now is how can I clear all of the items every time a specific button click?</p>