none
How to take each individual line from a TextBox and place it into an individual Column of a List View. (Vb.net Windows Forms) RRS feed

  • Question

  • Hi,

    I've looked all over the place and can't seem to find an appropriate answer, basically, all I want to do, is take each individual line from a TextBox (See diagram) and place it into an individual column of a ListView (See diagram)

    The TextBox and the ListView have all ready been created, so I just need to know how to transfer the information.

    Diagram:


    Thanks,

    Dan

    Sunday, June 9, 2019 5:23 PM

Answers

  • Hi

    Here is another offering: this does the copy on a Button1 Click

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim items As New ListViewItem(TextBox1.Lines(0))
      For i As Integer = 1 To TextBox1.Lines.Count - 1
    	items.SubItems.Add(TextBox1.Lines(i))
      Next
      ListView1.Items.Add(items)
    End Sub


    Regards Les, Livingston, Scotland

    Sunday, June 9, 2019 5:51 PM

All replies

  • Hello,

    Given three columns

    ListView1.Items.Add(TextBox1.Lines(0))
    ListView1.Items.Add(TextBox1.Lines(1))
    ListView1.Items.Add(TextBox1.Lines(2))

    With assertion

    If TextBox1.Lines.Count() => 3 Then
        ListView1.Items.Add(TextBox1.Lines(0))
        ListView1.Items.Add(TextBox1.Lines(1))
        ListView1.Items.Add(TextBox1.Lines(2))
    End If


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, June 9, 2019 5:49 PM
    Moderator
  • Hi

    Here is another offering: this does the copy on a Button1 Click

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim items As New ListViewItem(TextBox1.Lines(0))
      For i As Integer = 1 To TextBox1.Lines.Count - 1
    	items.SubItems.Add(TextBox1.Lines(i))
      Next
      ListView1.Items.Add(items)
    End Sub


    Regards Les, Livingston, Scotland

    Sunday, June 9, 2019 5:51 PM
  • Yep, that did it, thank you.

    :)

    Sunday, June 9, 2019 5:53 PM