title: I want to update 7 progress bars in C# list view at the same time
body: <p>I put the progress bar in the list view and implemented each update.
  I want to run the 7 progress bars inserted in the list view at the same time using a background worker.
  Help me how to do it</p>
  <pre class="lang-cs prettyprint-override"><code>private void button1_Click(object sender, EventArgs e)
  {
      backgroundWorker1 = new BackgroundWorker();
      backgroundWorker1.WorkerReportsProgress = true;
      backgroundWorker1.WorkerSupportsCancellation = true;
  
      backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
      backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
      backgroundWorker1.RunWorkerCompleted += new
          RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
      backgroundWorker1.RunWorkerAsync();
  }
  </code></pre>
  <p>I want to update the program bar of a total of 7 columns through the background worker.
  The purpose is to express file copying and completion status at the same time</p>
  <pre class="lang-cs prettyprint-override"><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  {
      int N = 7;
      ListView listview1 = null;
      this.Invoke(new MethodInvoker(delegate { listview1 = listview1; }));
      ListViewItem lvi;
      ProgressBar pb;
  
      for (int i = 0; i &lt; 100; i++)
      {
          if (backgroundWorker1.CancellationPending)
          {
              e.Cancel = true;
              return;
          }
  
          UpdateItemValue(i.ToString(), i);
          backgroundWorker1.ReportProgress(i * 100 / listView1.Items.Count, i);
      }
      e.Result = N;
  }
  
  private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      listView1.Items[0].SubItems[3].Text = &quot;Done&quot;;
  }
  
  private void UpdateItemValue(string key, int value)
  {
      //There is also a cross-thread problem in the UpdateItemValue method[enter image description 
      //here][1]
      ListViewItem lvi;
      ProgressBar pb;
  
      lvi = listView1.Items.Cast&lt;ListViewItem&gt;().FirstOrDefault(q =&gt; q.SubItems[0].Text == key);
      if (lvi != null)
          lvi.SubItems[2].Text = value.ToString();
  
      pb = listView1.Controls.OfType&lt;ProgressBar&gt;().FirstOrDefault(q =&gt; q.Name == key);
      if (pb != null)
          pb.Value = value;
  }
  </code></pre>
  <p>This method adds a column to the list view and adds a progress bar.</p>
  <pre class="lang-cs prettyprint-override"><code>private void Additem_Click(object sender, EventArgs e)
  {
      ListViewItem lvi = new ListViewItem();
  
      if (listView1.Items.Count &gt; 0)
      {
          listView1.BeginUpdate();
  
          lvi.Text = listView1.Items.Count.ToString();
          lvi.SubItems.Add(&quot;111&quot;);
  
          lvi.SubItems.Add(&quot;222&quot;);
          lvi.SubItems.Add(&quot;333&quot;);
          listView1.Items.Add(lvi);
  
          ProgressBar pb = new ProgressBar();
          Rectangle r = lvi.SubItems[2].Bounds;
          pb.SetBounds(r.X, r.Y, r.Width, r.Height);
          pb.Minimum = 0;
          pb.Maximum = 100;
          pb.Value = 0;
          pb.Name = listView1.Items.Count.ToString();                   // use the key as the name
          listView1.Controls.Add(pb);
          listView1.EndUpdate();
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/lteI7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lteI7.png" alt="1" /></a></p>
  <p>What I want to do with this code
  When you insert 7 progress bars in the list view and click the update button
  At the same time, you are moving the 7 progress bars in Lisview until they reach 100%.</p>