title: Making mouse click copy paste to work in all listviews
body: <p>I've been programming an application with C#. The app has multiple listviews and I'd like to make it possible to copy text  from any of them with as little code as possible. Currently my copy menu only works with one of the listviews. Here is my code:</p>
  
  <p>Code to copy data:</p>
  
  <pre><code>private void toolStripMenuItem1_Click(object sender, EventArgs e)
  {
      //ListView listView = sender as ListView; &lt;---- this didnt work
      if (listViewOrders.SelectedItems.Count &gt;= 1)
      {
          Clipboard.Clear();
          StringBuilder buffer = new StringBuilder();
  
          // Build the data row by row
          foreach (ListViewItem item in listViewOrders.SelectedItems)
          {
              buffer.Append(item.SubItems[0].Text.ToString());
              buffer.Append("\n");
          }
          Clipboard.SetText(buffer.ToString());
      }
  }
  </code></pre>
  
  <p>Code to create copy menu when clicked:</p>
  
  <pre><code>private void listViewOrders_MouseClick(object sender, MouseEventArgs e)
  {
      ListView listView = sender as ListView;
  
      if (e.Button == System.Windows.Forms.MouseButtons.Right)
      {
          ListViewItem item = listView.GetItemAt(e.X, e.Y);
  
          if (item != null)
          {
              item.Selected = true;
              contextMenuStrip1.Show(listView, e.Location);
          }
      }
  }
  </code></pre>