0

我想在 VB.net 中将每个文本分成它们自己的列。

我如何实现这一目标?

屏幕截图

每个主菜都用“|”分隔 . 我的代码:

 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
4

1 回答 1

0

目前我没有任何移动应用程序可供试验,但我相信你所追求的是这样的:

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

我可能误解了您要执行的操作,但我认为您正在尝试获取列条目。

更新:

既然您已将设置保存到文件中,您将如何取回它们?

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

当然,您的代码可能需要进行特殊处理,但这涵盖了基本的读写操作。

于 2012-04-16T00:51:50.147 回答