Reputation: 65
I have a simple form with 2 labels, 2 textboxes, 1 button and 1 listview. In the textboxes I want to input the names and ages of people.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Col1 As String = TextBox1.Text
Dim Col2 As String = TextBox2.Text
Dim lvi As New ListViewItem
lvi.Text = Col1
lvi.SubItems.Add(Col2)
ListView1.Items.Add(lvi)
End Sub
End Class
I got this code working, but when I input more than 1 name in textbox1 and more than 1 age in textbox2 the output in listview will be horizontal. And I want it to be vertical. Textboxes are multiline
Upvotes: 0
Views: 1732
Reputation: 1286
Split the value supplied from textbox1 and textbox2 using the CRLF. Aggregate each row from textbox1 and textbox2 to create each ListViewItem, looping for each row.
Dim tb1 As String() = Split(TextBox1.Text, vbCrlf)
Dim tb2 As String() = Split(TextBox2.Text, vbCrlf)
For i = 0 To tb1.Length - 1
Dim lvi As New ListViewItem
lvi.Text = tb1(i)
lvi.SubItems.Add(tb2(i))
ListView1.Items.Add(lvi)
Next
Upvotes: 1