I need to populate a listbox from a textfile that contains data from a workshop class.
The class contains the definitioin of the properties (FIELDS) of the workshop class.

The text file looks like this.
0\3\800\Programming in Java
0\3\800\Programming in Visual Basic
0\3\800\Programming in C#
0\5\1500\Advanced Java
0\5\1500\Advanced Visual Basic
0\5\1500\Advanced C#
0\5\1500\Web Application Programming
1\3\700\Intro to Networking
1\5\1900\Advanced Netwworking
1\3\600\Mobile Networking
2\5\2000\Introduction to Databases
2\4\2000\Database Administration
3\3\670\Intro to Unix/Linux

The items displayed in the listbox need to look like
Programming in Java = Days = 3, Category = Application development, Cost = $800.00
etc...

more info

Category is enumerated and is in column(0)
Days is column(1)
cost is column (2)
Title is column(3)

I'm retired but studying .net 2010 using "Advanced Visual Basic 2010" and this is one of the exersizes
and I've tried many different approaches and seem to be missing something.

All this is in VB 2010.

Any help is appreciated.

You can use split() to specify the delimiter in your text file which is "\" then save each item to an array.

You'll need a while loop that checks for end of file(eof), then read the file line by line. Use split, like was mentioned, to get each part into an array. The step to this point are pretty standard. From here you can build the row for the listbox by picking which elements of the array you want and in what order.

Edited 3 Years Ago by tinstaafl

If the requirement is not a ListBox then you might want to consider a ListView in Details mode. Using a ListView allows you to have column headers and you have more control over placement and sorting. To add your items to a listview you can do

Dim flds() As String = "Programming in Java\3\Application development\$800.00".Split("\")

ListView1.Items.Add(New ListViewItem(flds))
ListView1.Items.Add(New ListViewItem({flds(3), flds(1), flds(0), flds(2)}))

The first Add adds all of the items in the array in the order in which they appear. The second Add adds items in the order you specify.

Good point Jim. Instead of storing it to your listbox, You can use listview.

I believed that it is easier :) But still, it's up to you.

This article has been dead for over six months. Start a new discussion instead.