我有一个功能,所以我可以选择数据表的行并跟踪我选择的行。但是,当它返回另一个数据表时,它会输入我向后选择的行。
因此,如果我1,2,3
在返回数据表时选择行,则行显示为3,2,1
以下是函数:
Private Function getCoordinates()
Dim dt As New DataTable
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("Command")
dt2.Columns.Add("Position")
Try
If selectedItems Is Nothing Then
For n = 0 To dt.Rows.Count - 1
r("Command") = dt.Rows.Item(n)("Mouse Command")
r("Position") = dt.Rows.Item(n)("Mouse Position")
dt2.Rows.Add(r)
Next
Else
For Each selectedItem As DataGridViewRow In selectedItems
Dim MouseIndex = Convert.ToString(selectedItem.Cells(0).Value)
Dim CoordIndex = Convert.ToString(selectedItem.Cells(1).Value)
r = dt2.NewRow()
r("Command") = MouseIndex
r("Position") = CoordIndex
dt2.Rows.Add(r)
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dt2
End Function
Wsa 只是想知道我将如何做到这一点,这样行就不会像它那样颠倒。