0

I am using Visual Basic 2008. I have a ListView and a DataGridView which have both 3 columns like ProductCode, ProductName & ProductPrice. Now I want to pass ListView values to DataGridView in the same sequence. I want that when I double click on any row in the ListView these row values inserted to DataGridView.

Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick 
    If Not ListView1.SelectedItems.Count = 0 Then 
         '// check if item is selected. 
        With ListView1.SelectedItems(0) 
            Dim lvItem() As String = {.Text, .SubItems(1).Text, .SubItems(2).Text} 
            '// get ListView selectedItem. 
            DataGridView1.Rows.Add(lvItem) '// add it to DataGridView. 
        End With 
    End If 
End Sub
4

2 回答 2

1

也许这会奏效

Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick 
    If Not ListView1.SelectedItems.Count = 0 Then 
         '// check if item is selected. 
        With ListView1.SelectedItems(0) 
            Dim lvItem() As String = {.Text, .SubItems(1).Text, .SubItems(2).Text} 
            '// get ListView selectedItem. 

            'Assumed that TableDGV as your DGV datasource

            TableDGV.Rows.Add(lvItem) '// add it to DataGridView. 
            DataGridView1.DataSource = TableDGV


        End With 
    End If 
End Sub
于 2013-06-29T07:11:22.760 回答
0

您应该在单击列表视图时检查该事件,并在该事件上创建编辑数据网格视图的内容:)

于 2013-06-29T06:51:21.247 回答