title: Listview taking too long to update C#
body: <p>I have a problem I have been stuck on for ages, was hopinh you can all help please.</p>
  
  <p>I have a listview which populates with data from my database upon the programs first load.</p>
  
  <p>In  my program I have a button which 'Refreshes' this listview by wiping all of the data out of the listview and running the same method which populates the listview upon program load.  However, this refresh button is taking far too long (about 10 seconds) to refresh.  </p>
  
  <p>How is it that the program can load in 2 seconds with the listview populated however when running the method again it takes much longer.</p>
  
  <p>Please see my attached code and suggest any changes, I apologise for the length.  Thank you.</p>
  
  <pre><code>public void AllHomeworkers()
  {
      //This updates the homeworkers listview to contain all the records from the homeworkers table.
  
      listHomeworkersAll.BeginUpdate(); //This uses the begin update process on the listview, this is used to stop flickering
      listHomeworkersAll.Items.Clear(); //Clears all the items from the listview
  
      // this takes the datatable returned from AllHomeworkers stored procedure.
      // It then loops through the datatable adding every row to the list view.
  
      DataTable dtHomeworkers = _businessLayer.AllHomeworkers();
      for (int i = 0; i &lt; dtHomeworkers.Rows.Count; i++)
      {
          DataRow drowHomeworkers = dtHomeworkers.Rows[i];
  
          if (drowHomeworkers.RowState != DataRowState.Deleted)
          {
              ListViewItem lvi = new ListViewItem(drowHomeworkers["StaffID"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Title"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Initials"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Forename"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Surname"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Address"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Address2"].ToString());
              lvi.SubItems.Add(drowHomeworkers["City"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Postcode"].ToString());
              lvi.SubItems.Add(drowHomeworkers["CostCentre"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Email"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Telephone"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Mobile"].ToString());
              lvi.SubItems.Add(drowHomeworkers["FMID"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Comments"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Leaver"].ToString());
              lvi.SubItems.Add(drowHomeworkers["LeavingDate"].ToString());
              lvi.SubItems.Add(drowHomeworkers["Base"].ToString());
              lvi.SubItems.Add(drowHomeworkers["NextVisit"].ToString());
              var deleted = drowHomeworkers["Deleted"].ToString();
              if (deleted != "")
              {
                  lvi.ForeColor = Color.Red;
              }
              listHomeworkersAll.Items.Add(lvi);
          }
      }
      listHomeworkersAll.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);  
      // this sorts the columns to the size of the largest object stored inside them.
  
      listHomeworkersAll.EndUpdate();
      // this ends the listview update process.
  }
  </code></pre>