如何将datagrid视图的值放到listview

如何将datagrid视图的值放到listview

本文介绍了如何将datagrid视图的值放到listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim lvt As ListViewItem
        If dataGrid2.SelectedRows.Count >= 0 Then

            For Each row As DataGridViewRow In dataGrid2.SelectedRows
                lvt = New ListViewItem()
                lvt.SubItems.Add(row.Cells(1).Value.ToString())
                lvt.SubItems.Add(row.Cells(2).Value.ToString())
                bookList.Items.Add(lvt)
            Next

        Else
            MsgBox("Select a Book!", MsgBoxStyle.Exclamation, "Warning")
        End If


    End Sub

推荐答案

For Each row As DataGridViewRow In dataGrid2.SelectedRows
  bookList.Items.Add(row.Cells(1).Value.ToString(),row.Cells(2).Value.ToString(),0)
Next


祝您编码愉快!
:)


Happy Coding!
:)


Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click



        If dataGrid2.SelectedCells.Count >= 0 Then

            For Each row As DataGridViewRow In dataGrid2.SelectedRows

                bookList.Items.Add(row.Cells(1).Value.ToString())
                bookList.Items.Add(row.Cells(2).Value.ToString())

            Next

        Else

            MsgBox("Select a Book!", MsgBoxStyle.Exclamation, "Warning")

        End If


这篇关于如何将datagrid视图的值放到listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 14:07