Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[VB.net] Populate textboxes from listview selected items

Status
Not open for further replies.

escuro19

Programmer
Oct 30, 2009
7
GB
Hi All.

I have a Form with listview of customer name. e.g. AAA, BBB, CCC, DDD, EEE. etc And 3 textboxes.

I want to be able to populate the textboxes when the user selects a customer. For example: If User selects AAA, textbox1.text = AAA, then if User selects CCC, textbox2.text = CCC etc.

I tired: (in a button on click event)
TextBox1.Text = Listview1.SelectedItems(0).Text
TextBox2.Text = Listview1.SelectedItems(1).Text
TextBox3.Text = Listview1.SelectedItems(2).Text

But this only works if the user selects 'all' 3 customers at once. I want to allow the User to populate the each textboxes depending on how many they select eg. 'Upto' 3 customers .

Any ideas how i can achieve this?

Many Thanks in Advance.
 
Try this
Code:
Select Case Listview1.SelectedIndex
    Case 0
        TextBox1.Text = Listview1.Items(0).Text
    Case 1
        TextBox2.Text = Listview1.Items(1).Text
    Case 2
        TextBox3.Text = Listview1.Items(2).Text
    Case Else
End Select

Good luck.
 
Ooops.. Sorry.

Code:
Select Case Listview1.SelectedItems.Count
    Case 0
        '
    Case 1
        TextBox1.Text = Listview1.SelectedItems(0).Text
    Case 2
        TextBox1.Text = Listview1.SelectedItems(0).Text
        TextBox2.Text = Listview1.SelectedItems(1).Text
    Case 3
        TextBox1.Text = Listview1.SelectedItems(0).Text
        TextBox2.Text = Listview1.SelectedItems(1).Text
        TextBox3.Text = Listview1.SelectedItems(2).Text
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top