Question Parse File Into Listview?

xxf8xx

New member
Joined
Nov 8, 2010
Messages
2
Programming Experience
Beginner
Hi everyone. I'm working on a project and am kind of new to parsing files as well as listviews. I was wondering if someone could help me out.

I am trying to parse a file. Here is an example of what I need to parse.

a:b:c:d:e:f:g
a:b:c:d:e:f:g
a:b:c:d:e:f:g

Each entity needs to be stored in it's respective column in the listview. So therefore I need to read the file in line by line.

Thanks for the help everyone!
 
Use a TextFieldParser. There are code examples in the MSDN documentation for the class. For each line you read you add a ListViewItem to the ListView and for each field in the line you add a ListViewSubItem to the item. Just note that the first field is used for the item itself and subsequent fields are used for the subitems.
 
Ok so I am able to loop through and display each field in a message box. I still cannot figure out how to add it all into the listview though. Here is what I am doing:

VB.NET:
For Each currentField In currentRow 
  
          ListViewApps.Items.Add(currentField)

Next

I thought this would put each field in it's own row, but nothing comes up at all. I also still need to figure out how to get the subitems in each row to be added as subitems rather than having everything come up in it's own row.
 
Here's what I said:
For each line you read you add a ListViewItem to the ListView
In your code, is 'currentField' a ListViewItem? You can't add just any old object to a ListView as you can with a ListBox or ComboBox. A ListView is a specialised control and it can contain only ListViewItems. Have you read the MSDN documentation for the ListView class? As always, if you want to use a particular type then the documentation for that type is the first place you look. Not surprisingly, the ListView documentation includes a code example that demonstrates, amongst other things, creating and adding items to a ListView.
 
Back
Top