title: DataGridView: Copy complete to clipboard
body: <p>I have a DataGridView in a .Net application (V4 C# VS2010) &amp; want to copy <strong>all the data</strong> to the clipboard on the click of a button. No problem -</p>
  
  <pre><code>private void copyToClipboard()
  {
      dataGridView1.SelectAll();
      DataObject dataObj = dataGridView1.GetClipboardContent();
      if (dataObj != null)
          Clipboard.SetDataObject(dataObj);
  }
  </code></pre>
  
  <p>Problem is that the user might already have some cells, rows etc selected on the DataGrid &amp; I don't really want to change that selection. The above obviously selects everything. I could dataGridView1.ClearSelection(); at the end which is marginally better but still doesn't achieve what's required.</p>
  
  <p>I can save the selected cells:</p>
  
  <pre><code>var mySelectedCells = dataGridView1.SelectedCells;
  </code></pre>
  
  <p>but how do I get those selected cells reselected on the DataGrid after the copy? Is there an easy way to get the selected cells collection back into the DataGrid? Perhaps there is a better way to get the whole grid copied to the clipboard in the first place without affecting presently selected cells?</p>