0

ユーザーが選択した行のデータグリッド ビューにある各セルにある情報を取得する必要があります。行を選択していますが、セル内の情報を取得するのに助けが必要です。現在DataGridVewRow { Index=7}、データが実際に文字列である場合と同じように返されます。これが私の機能です

Private Function getCoordinates()
    Dim dt As New DataTable
    Dim dt2 As New DataTable
    'Dim r As DataRow
    Dim n As Integer = 0
    Dim selectedItems As DataGridViewSelectedRowCollection = dgv.SelectedRows
    dt = dgv.DataSource
    dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
    dgv.MultiSelect = True
    Dim i = dgv.CurrentRow.Index




    dt2.Columns.Add("Position")
    Try

        If selectedItems Is Nothing Then
            For n = 0 To dt.Rows.Count - 1
                dt2.Rows.Add(n)
                dt2.Rows(n)("Position") = dt.Rows.Item(n)("Mouse Position")
            Next

        Else

            For Each selectedItem As DataGridViewRow In selectedItems


                dt2.Rows.Add(selectedItem)
                dt2.Rows(selectedItem.Index)("Position") = dt.Rows.Item(selectedItem.Index)("Mouse Position")

            Next
        End If

    Catch ex As Exception
        MsgBox("Error", MsgBoxStyle.Exclamation, "Error!")
    End Try


    Return dt2


End Function
4

1 に答える 1