将Listview项目添加到另一个表单的文本框中

时间:2018-10-06 03:01:43

标签: vb.net

  

我的第一个表单是 frmBlotterAddEdit

这是我的第二种形式的代码

Private Sub lvmembers_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lvmembers.MouseDoubleClick
    frmBlotterAddEdit.txtFirst.Text = lvmembers.SelectedItems(0).SubItems(1).Text()
    frmBlotterAddEdit.txtMid.Text = lvmembers.SelectedItems(0).SubItems(2).Text()
    frmBlotterAddEdit.txtLast.Text = lvmembers.SelectedItems(0).SubItems(3).Text()
    frmBlotterAddEdit.txtHouse.Text = lvmembers.SelectedItems(0).SubItems(4).Text()
    frmBlotterAddEdit.txtStreet.Text = lvmembers.SelectedItems(0).SubItems(5).Text()
    frmBlotterAddEdit.txtBlock.Text = lvmembers.SelectedItems(0).SubItems(6).Text()

    Dim frm As New frmBlotterAddEdit
    frm.GroupBox1.Refresh()
    Me.Close()
End Sub

当我双击列表视图时,什么也没发生。

1 个答案:

答案 0 :(得分:1)

在MouseDoubleClick事件中隐藏第二个表单。然后以您的第一种形式进行处理。

第二种形式:

Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListView1.MouseDoubleClick
    Me.Hide()
End Sub

第一种形式:

Private Sub Show2ndFormButton_Click(sender As Object, e As EventArgs) Handles Show2ndFormButton.Click

    Try

        Dim f2 As New Form2
        f2.ShowDialog()
        TextBox1.Text = f2.ListView1.SelectedItems(0).Text
        f2.Close()

    Catch ex As Exception

        MessageBox.Show(String.Concat("An error occurred: ", ex.Message))

    End Try

End Sub