Hey :)

Im working on a project and ive come across a small problem. I have a listview that contains the details of a person(s) such as their name,address,e-mail address etc. I have a button that opens up another form where the user can edit the details of the customer, but for this too work i have to type in the ID number of the person.

I want the user to be able to select a person from the listview, click on edit and then the details are transfered to the edit customer form without having to type in the persons ID number. I was wonderinf how i would be able to do that because im really confused.

Thanks :)

See if this helps.
2 Forms (1 Button on Form1, 3 TextBoxes on Form2)

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ListView1.SelectedItems.Count = 1 Then '// check if only 1 item is selected.
            With ListView1.SelectedItems(0) '// with Selected item.
                Form2.TextBox1.Text = .Text '// item text.
                Form2.TextBox2.Text = .SubItems(1).Text '// item column 2.Text
                Form2.TextBox3.Text = .SubItems(2).Text '// item column 3.Text
                Form2.ShowDialog()
            End With
        ElseIf ListView1.SelectedItems.Count = 0 Then '// if no item selected.
            MsgBox("Please select an item to edit.")
        ElseIf ListView1.SelectedItems.Count > 1 Then '// for "MultiSelect=True" ListViews.
            MsgBox("Please select only one item to edit.")
        End If
    End Sub
End Class
Public Class Form2
    '// save edited item back to ListView.
    Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        With Form1.ListView1.SelectedItems(0)
            .Text = TextBox1.Text : .SubItems(1).Text = TextBox2.Text : .SubItems(2).Text = TextBox3.Text
        End With
    End Sub
End Class
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.