问题
I want to separate each text into their own Column in VB.net.
How do I achieve this?

Each entree is seperated with "|" . My Code:
Private Sub MenuItem3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim folder As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
Using sw As StreamWriter = File.AppendText("\My Expenses.txt")
sw.WriteLine(DateTimePicker.Text + Space(1) & "|" & Subject.Text + Space(4) & "|" & Category.Text + Space(5) & "|" & Amount.Text + Space(4) & "|" & Peyment.Text)
sw.Close()
End Using
End Sub
回答1:
I do not have any mobile apps to experiment on at this moment, but I believe something like this is what you are after:
Private Sub MenuItem3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Using sw As StreamWriter = File.AppendText("\My Expenses.txt")
For Each item As ListViewItem in ListView1
Dim line As String = Nothing
For Each entry As String in item.SubItems
line.Append(entry & "|")
Next For
sw.WriteLine(line)
Next For
sw.Close()
End Using
End Sub
I may have misunderstood what you are trying to do, but I think you are trying to get the column entries.
Update:
Now that you have saved the settings to a file, how would you get them back?
Private Sub PopulateListView()
ListView1.Items.Clear()
Using sr As StreamReader = File.OpenText("\My Expenses.txt")
While (-1 < sr.Peek())
Dim line As String = sr.ReadLine()
Dim item As New ListViewItem(line.Split("|"c))
ListView1.Items.Add(item)
End While
sr.Close()
End Using
End Sub
Naturally, your code may have special handling that is required, but this covers the basic read and write operations.
来源:https://stackoverflow.com/questions/10162262/separating-text-from-txt-into-colums-in-listview-vb-net-mobile