0
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

""sir if i click example 5 items??? because i have many texboxes... look like this..
Item #
textbox1
textbox2
textbox3
textbox4
textbox5

??
thnx :)

Edited by Narue: Added code tags

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.