Separating text from .txt into colums in listview (VB.net mobile)

a 夏天 提交于 2019-12-13 05:53:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!