如何保存/打开列表视图中的文本文件? [英] How do I save/open text files that are in a listview?

查看:56
本文介绍了如何保存/打开列表视图中的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用listview控件。由于我创建的软件是商业级软件,它是一个项目经理(围绕预算编制),我需要知道如何在文本文件中保存和打开列表视图。这是到目前为止我只需要b $ b:

This is my first time working with the listview control. Since the software I am creating is business grade and it is a project manager(which revolves around budgeting), I need to know how to save and open the listview to/from a text file. This is what I have so far:

    Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
        OpenFileDialog1.ShowDialog()
        Dim File As New RichTextBox
        File.Text = IO.File.ReadAllText(OpenFileDialog1.FileName)
        For Each line As String In File.Lines
            If line = "-" Then
                Item = ListView1.Items.Add(File.Lines(i + 1))
                Item.SubItems.Add(File.Lines(i + 2))
            End If
        Next
    End Sub

    Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
        Dim File As New RichTextBox
        For Each saveitem As ListViewItem In ListView1.Items
            File.AppendText("-" & vbNewLine & saveitem.Text & vbNewLine & saveitem.SubItems(1).Text)
        Next
        SaveFileDialog1.ShowDialog()
        File.SaveFile(SaveFileDialog1.FileName)
    End Sub

每当我去调试项目时,我都无法将文本文件导入列表视图,每当我保存文本文件时,它都会为每一行添加/ par。

Whenever I go to debug the project, I cannot import the text file into the listview, and whenever I save the text file, it adds /par to every line.

一些小事:a)有没有人知道如何打印列表视图,然后知道"价格"中的项目总数。列和b)哪个版本是第一个支持listview控件的版本,所以我可以在我的网站上创建一个最低要求部分?

A couple small things: a) does anyone know how to print the listview and then the total of the items in the "price" column and b) what version is the first to support the listview control so I can create a minimum requirements section on my website?

推荐答案

这不是Visual Studio的问题所以Visual Studio General Questions论坛不是问题所在。

This is not a Visual Studio question so the Visual Studio General Questions forum is not the place fro the question.

您需要决定数据的来源被保存(存储)在磁盘上。您可以使用数据库,也可以使用XML,也可以使用JSON,或者使用分隔文件(如CSV或制表符分隔文件)。

You need to decide how the data is to be persisted (stored) on a disk. You could use a database or you could use XML or you could use JSON or you could use a delimited file such as a CSV or a tab-delimited file.

如果需要创建"商业等级"然后你应该了解实体框架。

If you need to create "business grade" applications then you should learn about the Entity Framework.


这篇关于如何保存/打开列表视图中的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆