Answered by:
Add Textbox.Lines To Listview....How???

Question
-
Hi Friends,
I have 3 textboxes with lines that I'm trying to add to 3 columns in a Listivew1. I am trying to get the TextBox1.Lines into Listview1 Column1, TextBox2.Lines into Listview1 Column2, & TextBox3.Lines into Listview1 Column3.
I have tried to put the TextBox.Lines into an array & send them into each column in the listview, but it's not working. Here's the code that I'm using:
Dim Item As ListViewItem For Each Product1 In TextBox1.Lines Item = ListView1.Items.Add(Product1) Next For Each Product2 In TextBox2.Lines Item.SubItems.Add(Product2) Next For Each Product3 In TextBox3.Lines Item.SubItems.Add(Product3) Next
Here's what my form looks like:
http://i.imgur.com/TN6cWXb.png?1
Numbers 1,2,3,4,& 5 from TextBox1.Lines should go into Column1
Numbers 6,7,8,9,&10 from TextBox2.Lines should go into Column2
Numbers 11,12,13,14,& 15 from TextBox3.Lines should go into Column3
I would appreciate a simple code snippet. Thanks again.
- Edited by AaronEsteban Friday, June 17, 2016 12:00 AM
Thursday, June 16, 2016 11:56 PM
Answers
-
Numbers 1,2,3,4,& 5 from TextBox1.Lines should go into Column1
Numbers 6,7,8,9,&10 from TextBox2.Lines should go into Column2
Numbers 11,12,13,14,& 15 from TextBox3.Lines should go into Column3
Dim lines() As String = TextBox1.Lines For I As Integer = 0 To 4 Dim LVI As New ListViewItem(lines(I)) LVI.SubItems.Add(lines(I + 5)) LVI.SubItems.Add(lines(I + 10)) ListView1.Items.Add(LVI) Next
- Marked as answer by Herro wongMicrosoft contingent staff Monday, June 27, 2016 12:01 PM
Friday, June 17, 2016 1:09 AM -
Hi
Here is some very basic code to do that.
' maybe you already have columns set up ListView1.Columns.Add("Column1") ListView1.Columns.Add("Column2") ListView1.Columns.Add("Column3") For i As Integer = 0 To TextBox1.Lines.Count - 1 ListView1.Items.Add(TextBox1.Lines(i)) ListView1.Items(i).SubItems.Add(TextBox2.Lines(i)) ListView1.Items(i).SubItems.Add(TextBox3.Lines(i)) Next
Regards Les, Livingston, Scotland
- Proposed as answer by Albert_Zhang Friday, June 17, 2016 2:21 AM
- Marked as answer by Herro wongMicrosoft contingent staff Monday, June 27, 2016 12:01 PM
Friday, June 17, 2016 12:55 AM
All replies
-
Hi
Here is some very basic code to do that.
' maybe you already have columns set up ListView1.Columns.Add("Column1") ListView1.Columns.Add("Column2") ListView1.Columns.Add("Column3") For i As Integer = 0 To TextBox1.Lines.Count - 1 ListView1.Items.Add(TextBox1.Lines(i)) ListView1.Items(i).SubItems.Add(TextBox2.Lines(i)) ListView1.Items(i).SubItems.Add(TextBox3.Lines(i)) Next
Regards Les, Livingston, Scotland
- Proposed as answer by Albert_Zhang Friday, June 17, 2016 2:21 AM
- Marked as answer by Herro wongMicrosoft contingent staff Monday, June 27, 2016 12:01 PM
Friday, June 17, 2016 12:55 AM -
Numbers 1,2,3,4,& 5 from TextBox1.Lines should go into Column1
Numbers 6,7,8,9,&10 from TextBox2.Lines should go into Column2
Numbers 11,12,13,14,& 15 from TextBox3.Lines should go into Column3
Dim lines() As String = TextBox1.Lines For I As Integer = 0 To 4 Dim LVI As New ListViewItem(lines(I)) LVI.SubItems.Add(lines(I + 5)) LVI.SubItems.Add(lines(I + 10)) ListView1.Items.Add(LVI) Next
- Marked as answer by Herro wongMicrosoft contingent staff Monday, June 27, 2016 12:01 PM
Friday, June 17, 2016 1:09 AM