我想这样做,以便根据用户在 datagridview 中选择的行创建一个新的数据表,但是我一直收到一个错误,说Unable to cast object of type 'System.Windows.Forms.DataGridViewRow' to type 'System.Windows.Forms.DataGridView
我不知道这意味着什么,我希望我能得到一些帮助。
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