I keep getting this error and I don't know what causes this error or how to fix it, can someone please help me out?
I get an error at the line
This line returns a string value
Code:
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
Dim x, y As Integer
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 index = Convert.ToString(selectedItem.Cells(0).Value)
r("Command") = index
r("Position") = dt.Rows(selectedItem.Cells(1).Value.ToString)("Mouse Position")
dt2.Rows.Add(r)
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Code:
r("Command") = index