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
            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

""sir if i click example 5 items??? because i have many texboxes... look like this..
Item #

thnx :)

Re: Automatically generate text boxes from a list view 80 80

Your source code do is it allows for only one item to be selected by user. The software then will show him; the selected items, and other two subitems in form2.

Perhaps thats not what you are hoping for, what do you want it to do?

Re: Automatically generate text boxes from a list view 80 80

YOu wanna pass data from ListView to the TextBoxes on some other Form (and create them as many as needed too)?

If so, 1st of all do NOT change Modifiers property to public. Leave them as private, and rather gather all the data from listView, put then into some collection (like genetic List<T>) and pass then to Form2 into constructor. There you create new TextBoxes, based on the number of items in a List<T>, and populate them from the list.

Be a part of the DaniWeb community

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