Hasanal
Hasanal

Reputation: 5

How do I insert DataGridView values from selected columns and rows into ListView?

I've just started learning VB.Net and im trying to move values from my DataGridView to ViewList. I followed some other tutorial online but I still couldn't solve it.

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

Upvotes: 0

Views: 219

Answers (1)

jdwee
jdwee

Reputation: 613

It looks like you're having trouble with the ListView item addition. It should look something like this:

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

Upvotes: 1

Related Questions