locked
listview to text box RRS feed

  • Question

  • How do I send information from the id column to the text box from listview when I click on button 2 ?

    Saturday, February 1, 2014 7:33 PM

Answers

  • Hi,

     I am guessing you want to get the text of the selected item. If so you can use the SlectedItems collection to get the text like this

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If ListView1.SelectedItems.Count > 0 Then
                TextBox1.Text = ListView1.SelectedItems(0).Text
            End If
        End Sub
    

    There is other ways you could use that would set the textboxes text to the selected item of the listview as you click on the item instead of pressing a button. Here is an example of that

        Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
            If ListView1.SelectedItems.Count > 0 Then
                TextBox1.Text = ListView1.GetItemAt(e.X, e.Y).Text
            End If
        End Sub
    

    • Proposed as answer by Frank L. Smith Saturday, February 1, 2014 8:23 PM
    • Marked as answer by Carl Cai Monday, February 10, 2014 9:41 AM
    Saturday, February 1, 2014 8:01 PM