[VB.net] Populate textboxes from listview selected items

escuro19

New member
Local time
Today, 05:37
Joined
Oct 30, 2009
Messages
5
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 each textboxes depending on how many they select eg. 'Upto' 3 customers .

Any ideas how i can achieve this?

Many Thanks in Advance.
 
You need to supply both the index number and the column number for the selected item in the list.
 
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 each textboxes depending on how many they select eg. 'Upto' 3 customers .

Any ideas how i can achieve this?

Many Thanks in Advance.

I would use something like this
Code:
[COLOR=#0000ff][COLOR=#0000ff]Private[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR] Button1_Click([COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] sender [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] System.Object, [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] e [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] System.EventArgs) [COLOR=#0000ff][COLOR=#0000ff]Handles[/COLOR][/COLOR] Button1.Click
[COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] lvc [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] ListView.SelectedListViewItemCollection = lvw.SelectedItems
TextBox1.Text = [COLOR=#a31515][COLOR=#a31515]""[/COLOR]
[/COLOR]TextBox2.Text = [COLOR=#a31515][COLOR=#a31515]""[/COLOR]
[/COLOR]TextBox3.Text = [COLOR=#a31515][COLOR=#a31515]""[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]For[/COLOR][/COLOR] cnt [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Integer[/COLOR][/COLOR] = 0 [COLOR=#0000ff][COLOR=#0000ff]To[/COLOR][/COLOR] lvc.Count - 1
[COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] lv [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] ListViewItem = lvc.Item(cnt)
[COLOR=#0000ff][COLOR=#0000ff]For[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Each[/COLOR][/COLOR] ctl [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] Control [COLOR=#0000ff][COLOR=#0000ff]In[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Me[/COLOR][/COLOR].Controls
[COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]TypeOf[/COLOR][/COLOR] ctl [COLOR=#0000ff][COLOR=#0000ff]Is[/COLOR][/COLOR] TextBox [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] txt [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] TextBox = [COLOR=#0000ff][COLOR=#0000ff]CType[/COLOR][/COLOR](ctl, TextBox)
[COLOR=#0000ff][COLOR=#0000ff]Select[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Case[/COLOR][/COLOR] lv.Index
[COLOR=#0000ff][COLOR=#0000ff]Case[/COLOR][/COLOR] 0
txt = TextBox1
txt.Text = lv.Text
[COLOR=#0000ff][COLOR=#0000ff]Case[/COLOR][/COLOR] 1
txt = TextBox2
txt.Text = lv.Text
[COLOR=#0000ff][COLOR=#0000ff]Case[/COLOR][/COLOR] 2
txt = TextBox3
txt.Text = lv.Text
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Select[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Next[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]Next[/COLOR]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [SIZE=3][COLOR=#0000ff][SIZE=3][COLOR=#0000ff][SIZE=2]Sub[/SIZE][/COLOR]
[/SIZE][/COLOR][/SIZE]

~'J'~
 

Users who are viewing this thread

Back
Top Bottom