Click here to Skip to main content
14,982,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone

I was wondering how can i make it so when a user clicks on a listview item all its subitems are output to a textbox. The code i have now works but only work for a particlar listview item, how can i make it so displays by the item the user chooses.

I know i have to uses a for loop.,.but still abit unsure.

With Me.ListView1
    For i As Integer = 0 To .SelectedItems.Count - 1
        Dim myString As String = ListView1.Items(i).SubItems(0).Text
        Dim myString1 As String = ListView1.Items(i).SubItems(1).Text
        Dim myString2 As String = ListView1.Items(i).SubItems(2).Text
        Dim myString3 As String = ListView1.Items(i).SubItems(3).Text
        Dim myString4 As String = ListView1.Items(i).SubItems(4).Text
        Dim myString5 As String = ListView1.Items(i).SubItems(5).Text
        txtsummary1.Text = myString1
        txtsummary2.Text = myString2
        txtsummary3.Text = myString3
        txtsummary4.Text = myString4
        txtsummary5.Text = myString5
    Next i
End With



any help would be great
Posted

1 solution

Firstly I set the Multi Select to false....

VB
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
       With Me.ListView1
           Dim i As Integer
            For Each item As ListViewItem In ListView1.SelectedItems
               i = item.Index
           Next

           Dim innercounter As Integer = 0
           For Each subItem As ListViewItem.ListViewSubItem In ListView1.Items(i).SubItems
               Dim myString As String = ListView1.Items(i).SubItems(innercounter).Text
               Select Case innercounter
                   Case 1
                       TextBox1.Text = myString
                   Case 2
                       TextBox2.Text = myString
                   Case 3
                       TextBox3.Text = myString
                   Case 4
                       TextBox4.Text = myString
                   Case 5
                       TextBox5.Text = myString
               End Select
               innercounter += 1
           Next
       End With
   End Sub
   
Comments
SIFNOk 28-Apr-11 6:11am
   
Thanks Roobbb! Works Like a Dreammm.
Rob Branaghan 28-Apr-11 6:13am
   
Your welcome! Glad I could help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900