title: Transferring one datagridview data to another datagridview in VB.NET
body: <p>Issue: Moving multiple rows and columns from one datagridview(non-data bound) to another datagridview and then displaying the second datagridview rows from another form which is data bound.</p>
  
  <p>Developing platform : VB.NET 2008</p>
  
  <p>Issue description:</p>
  
  <ul>
  <li>I have some rows and columns in another form's datagridview which is now populated from a local database that is now connected in my application.</li>
  <li>Having an error in EncodingCompleteDataSet inside the Update argument, which says 'Error 1 'EncodingCompleteDataSet' is a type and cannot be used as an expression.'</li>
  <li>Where would I insert <code>anotherForm.Show()</code> in the following code?</li>
  </ul>
  
  <p>Issue Code:</p>
  
  <pre><code>Dim dr = DirectCast(DataGridViewX1.Rows(e.RowIndex).DataBoundItem, System.Data.DataRowView).Row
  frmEncodeDatabase.EncodingCompleteDataSet.Tables("EncodingComplete").ImportRow(dr)
  EncodingCompleteDataSetTableAdapters.EncodingCompleteTableAdapter.Update(EncodingCompleteDataSet, "EncodingComplete")
  </code></pre>
  
  <p>Regards,
  CodingSource</p>
  
  <p><strong><em>EDIT: For Jason Faulkner</em></strong></p>
  
  <p>Code:</p>
  
  <pre><code>For Each Col As DataGridViewColumn In DataGridViewX1.Columns
          frmEncodeDatabase.EncodingCompleteDataGridView.Columns.Add(DirectCast(Col.Clone, DataGridViewColumn))
      Next
      frmEncodeDatabase.EncodingCompleteDataGridView.Rows.Add(DataGridViewX1.Rows(0).Cells.Cast(Of DataGridViewCell).Select(Function(c) c.Value).ToArray)
  </code></pre>
  
  <p>Your code (which I altered a little):</p>
  
  <pre><code>Dim table As DataTable = DirectCast(frmEncodeDatabase.EncodingCompleteDataGridView.DataSource, DataView).Table
  
      ' Add row 0 to the DataGridViewX1 grid to the table.
      ' This assumes the schema/column names are the same between the two.
      Dim addRow As DataRow = table.NewRow
      For Each Col As DataGridViewColumn In DataGridViewX1.Columns
          addRow(Col.Clone) = frmEncodeDatabase.EncodingCompleteDataGridView.Rows(0).Cells(Col.Clone).Value
      Next
  
      ' Add the copied row values to the table.
      ' Once we do this, it should appear in the EncodingCompleteDataGridView.
      table.Rows.Add(addRow)
  </code></pre>
  
  <p>But I'm having an error in <code>table As DataTable = DirectCast(frmEncodeDatabase.EncodingCompleteDataGridView.DataSource, DataView).Table</code>which says </p>
  
  <blockquote>
    <p>InvalidCastException was unhandled: Unable to cast object of type
    'System.Windows.Forms.BindingSource' to type 'System.Data.DataView'.</p>
  </blockquote>