Search code examples
vb.netlistboxfileopendialog

How to load data into listbox from text box?


HI I need a little help.

Part of my Problem:

  • First, Read a text file.
  • Add the items from text file into TextBox and ListBox.

Sample Data in my text file is like this:

A;Cat;Dog;Rat;Bird

Where, ";" is the Delimiter and data is just one line only.
"A" has to load in TextBox and "Cat,.....,Bird" has to load in ListBox, one line per animal. I've already read the text file and load "A" into text box.
But couldn't figure out how to load rest of the data into list box.

Any help would be great.


Solution

  • This is really simple and you should have a look at the MSDN page to learn more on ListBox and other related stuff.

    Dim str As String = "A;Cat;Dog;Rat;Bird"  'should have read from your text file
    
    Dim arr As String() = str.Split(New Char() {";"})
    Dim i As Integer
    For i = 1 To arr.Length - 1
         ListBox1.Items.Add(arr(i))
    Next i