none
Textbox To Listbox

    Question

  • I want a textbox's text to be moved line by line to a list box.

    textbox1.text:

    car

    bike

     

    future listbox text:

    car bike

    how to i do this

    Wednesday, July 07, 2010 3:04 PM

Answers

  • do you want the ListBox items like how you show: car, bike  (all in one line)

    or on separate lines?

    either way, all you need to do is loop through the TextBox Lines property with something like a For Each loop and add each to the ListBox, in whatever format you want

    Wednesday, July 07, 2010 3:11 PM
  • Hello RollsRoycePhantom95,
    Thanks for your post.
    This is textbox1'text
    car
    bike
    You want to move textbox1's text to listbox. Its items like this:
    car
    bike
    Is it right? If I understand your problem correctly, please try the following code. Hope it helpful.

    Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)
    For Each item As String In NewArray
       ListBox1.Items.Add(item)
    Next

    If you have any problems, please feel free to follow up.
    Best regards,
    Liliane

     


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Proposed as answer by Renee Culver Monday, July 12, 2010 1:53 PM
    • Marked as answer by Liliane Teng Wednesday, July 14, 2010 5:47 AM
    Monday, July 12, 2010 1:47 PM
  • without a loop

    ListBox1.Items.AddRange(Split(textbox1.text, vbCrLf))

    Success
    Cor
    Monday, July 12, 2010 2:14 PM

All replies

  • do you want the ListBox items like how you show: car, bike  (all in one line)

    or on separate lines?

    either way, all you need to do is loop through the TextBox Lines property with something like a For Each loop and add each to the ListBox, in whatever format you want

    Wednesday, July 07, 2010 3:11 PM
  • do you want the ListBox items like how you show: car, bike  (all in one line)

    or on separate lines?

    either way, all you need to do is loop through the TextBox Lines property with something like a For Each loop and add each to the ListBox, in whatever format you want

    separate
    Wednesday, July 07, 2010 5:03 PM
  • Hello RollsRoycePhantom95,
    Thanks for your post.
    This is textbox1'text
    car
    bike
    You want to move textbox1's text to listbox. Its items like this:
    car
    bike
    Is it right? If I understand your problem correctly, please try the following code. Hope it helpful.

    Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)
    For Each item As String In NewArray
       ListBox1.Items.Add(item)
    Next

    If you have any problems, please feel free to follow up.
    Best regards,
    Liliane

     


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Proposed as answer by Renee Culver Monday, July 12, 2010 1:53 PM
    • Marked as answer by Liliane Teng Wednesday, July 14, 2010 5:47 AM
    Monday, July 12, 2010 1:47 PM
  • You can do this by

     

    Listbox1.items.add(textbox1.text)

    • Proposed as answer by David 75 Wednesday, March 20, 2013 9:26 PM
    Monday, July 12, 2010 1:55 PM
  • without a loop

    ListBox1.Items.AddRange(Split(textbox1.text, vbCrLf))

    Success
    Cor
    Monday, July 12, 2010 2:14 PM