title: Copy a DataGridView
body: <p>I'm trying to take a copy of a DataGridView.</p>
  
  <pre><code>Public Sub CopyDataView(ByVal inGrid As DataGridView,
                          ByVal inPrintHiddenCols As Boolean)
      DataGridView1 = inGrid
  </code></pre>
  
  <p>I then alter the configuration of DataGridView1 then do:</p>
  
  <pre><code>    DataGridView1.Refresh()
      DataGridView1.Visible = True
  </code></pre>
  
  <p>The problem I'm having is done to DataGridView1 and only the Original grid is changed and refreshed.  This is despite the fact that the original grid is passed ByVal.</p>
  
  <p>I've tried processing the passed grid, column, by column, row by row, but I get the error</p>
  
  <pre><code>"Provided column already belongs to the DataGridView control"
  </code></pre>
  
  <p>The DataGridView1 is initialized </p>
  
  <pre><code>    Cursor.Current = Cursors.WaitCursor
      Try
          DataGridView1.Columns.Clear()
          DataGridView1.Rows.Clear()
          DataGridView1.AutoSize = True
          DataGridView1.AutoGenerateColumns = False
          DataGridView1.RowHeadersVisible = False
  
              For Each col As DataGridViewColumn In inGrid.Columns
              If col.Width = 0 Or _
                 col.Displayed = False And _
                 Not (inPrintHiddenCols) Then
                  SkipCells.Add(col.Index)
              Else
                  Dim c As New DataGridViewColumn
                  c = col
                  DataGridView1.Columns.Add(c)  ' &lt;----------------------
                  ColWidth_CSV.Add(modFunctions.GetWidthOfText(col.Width, f))
              End If
          Next
  </code></pre>
  
  <p>on the first column to be added. I've searched all the instances of this error, but the only solutions say "Copy the DataSource", there is no DataSource, this is a generated table. I can't find a way to transform the DataGridView data into a DataSource either.</p>
  
  <p>What am I missing? Any suggestions?</p>