Okay, Heres my senario and im having difficulty trying to picture the logic to make it work...
I have a file with the following:
ADDRESS1
CITY1
STATE1
ZIP1
ADDRESS2
CITY2
STATE2
ZIP2
And each line is different, I need to loop the ADDRESS, CITY, STATE, ZIP and put them in a listview as columns horizontal... ie.
Address, City, State, Zip
Right now im loading the file above as textbox1.text .... and iterating to add each line but that only adds a single column, how do I make that add to all columns!?
example Listview should look like:
Address City State Zipcode
ADDRESS1 CITY1 STATE1 ZIP1
ADDRESS2 CITY2 STATE2 ZIP2
.... etc .....
AlanPosted Jul 9, 2008, 7:32 PM
As long as the lines with less than 2 characters don't denote information which is missing, you'd just have to filter them out first:
Dim
lines As String() = System.IO.File.ReadAllLines("c:\jayson.txt") Dim temp As New List(Of String)temp.AddRange(lines)
For i As Integer = temp.Count - 1 To 0 Step -1 If temp(i).Length < 2 Then temp.RemoveAt(i) Nextlines = temp.ToArray()
Dim numRows As Integer = lines.Length \ 4 ' etcJayson BPosted Jul 9, 2008, 7:18 PM
hey thanks for that; how would I use the same exampel to check for lines greater than 1 ? ie. no null lines.. sometimes there are null lines, but states are 2 letters... so i need more than 1 ..
ie. lines.length > 1
AlanPosted Jul 9, 2008, 3:31 PM
Try something like this:
Dim
lines As String() = System.IO.File.ReadAllLines("c:\my documents\jayson.txt") Dim numRows As Integer = lines.Length \ 4 Dim address, city, state, zip As String Dim item As ListViewItem For i As Integer = 0 To numRows - 1address = lines(i * 4)
city = lines(i * 4 + 1)
state = lines(i * 4 + 2)
zip = lines(i * 4 + 3)
item =
New ListViewItem(address, 0)item.SubItems.Add(city)
item.SubItems.Add(state)
item.SubItems.Add(zip)
ListView1.Items.Add(item)
Next