如何将选定列和行中的DataGridView值插入ListView?

时间:2017-12-26 18:01:13

标签: vb.net datagridview

我刚刚开始学习VB.Net并试图将值从我的DataGridView移动到ViewList。我在线跟踪了一些其他教程,但我仍然无法解决。

Private Sub DataGridView1_CellContentClick(sender As System.Object, e As DataGridViewCellEventArgs) Handles dgvGPU.CellContentClick
    Dim senderGrid = DirectCast(sender, DataGridView)

    If TypeOf senderGrid.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso
       e.RowIndex >= 0 Then

        Dim x As String = dgvGPU.Rows[e.RowIndex].Cells[5].Value.ToString()

        Form4.ListView1.Items.Add(x)
        Form4.Show()
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

看起来你在添加ListView项目时遇到了麻烦。看起来应该是这样的:

ListView1.Items.Add(New ListViewItem(New String() {x}))