Hi,

I have a listbox that is connected to a text file and this file is created when the program opens for the first time and then users can add data to the file as they wish. However what I am having a problem with is that how can I link the selected item in the listview to a textbox.

I.e.

Listview has 3 columns: Name, Surname and Location

Then when the line is selected i want the 3 individual variables to display in 3 seperate text boxes that has been set up.

Any help would be greatly appreciated.

Recommended Answers

All 3 Replies

Perfect. Had to change it a little to work with the following code:

Private Sub ListViewSelection()

        If lvLocations.SelectedItems.Count > 0 Then
            Dim list As ListViewItem = lvLocations.SelectedItems(0)
            'Check whether subitems exists
            If list.SubItems.Count >= 1 Then
                'Here also check whether they are empty
                If list.SubItems(1).Text <> "" Then
                    'MsgBox(list.Text & " " & list.SubItems(1).Text)
                    'tbTest.Text = list.Text & " " & list.SubItems(1).Text
                    tbPNID.Text = list.Text
                    tbDID.Text = list.SubItems(1).Text
                    tbDPID.Text = list.SubItems(2).Text
                Else
                    MsgBox("Incomplete")
                End If
            Else
                MsgBox("Incomplete")
            End If
        End If

    End Sub

so now what is your problem in this code??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.