将值从listview传递到文本框

时间:2013-11-16 19:09:24

标签: vb.net visual-studio-2010

我一直在努力解决这个问题,并发布了一个问题让我走到了这一步。当我单击listview中的条目时,我无法将listview值添加到add子文件中的文本框中。它让我疯了,如果有人能指出我的错误,那将是感激的。感谢

需要填充这些文本框

Sub add()
        Try
            While dr.Read()
                txtname.Text = dr(0)
                txtfathername.Text = dr(1)
                txtaddress.Text = dr(2)
                txtemail.Text = dr(3)
            End While
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

Listview代码

Sub filllistview()
        Try
            'creatconn()
            cn.Open()
            Dim cmd As OleDbCommand = New OleDbCommand("Select * from Postings", cn)
            dr = cmd.ExecuteReader()
            While dr.Read()

                ListView1.Items.Add(dr(0).ToString())
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(dr(1).ToString())
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(dr(2).ToString())
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(dr(3).ToString())

            End While

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        Finally
            dr.Close()
            cn.Close()
        End Try
    End Sub

1 个答案:

答案 0 :(得分:0)

  Private Sub lstPosting_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstPosting.MouseClick
       Textbox1.Text = lstPosting.SelectedItems.Item(0).Text
   End Sub