title: Fixing Unknown Error
body: <p>I want to make it so a new datatable gets created based on what rows the user selects in the datagridview, however I keep getting an error saying <code>Unable to cast object of type 'System.Windows.Forms.DataGridViewRow' to type 'System.Windows.Forms.DataGridView</code>
  I have no clue what this means, and I was hoping I could get some help.</p>
  
  <pre><code>Private Function getCoordinates()
  
      Dim dt2 As New DataTable
      'Dim r As DataRow
      Dim n As Integer
      Dim selectedItems As DataGridViewSelectedRowCollection = dgv.SelectedRows
      dt = dgv.DataSource
      dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
      dgv.MultiSelect = True
  
  
      dt2.Columns.Add("Position")
      Try
          For Each selectedItem As DataGridView In selectedItems
              dt2.Rows.Add(n)
              dt2.Rows(n)("Position") = dt.Rows.Item(n)("Mouse Position")
          Next
  
  
      Catch ex As Exception
          MsgBox("Error", MsgBoxStyle.Exclamation, "Error!")
      End Try
  
  
      Return dt2
  </code></pre>