Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 用分隔符在VB中保存listview的列_Vb.net - Fatal编程技术网

Vb.net 用分隔符在VB中保存listview的列

Vb.net 用分隔符在VB中保存listview的列,vb.net,Vb.net,所以我有一个listview,它有两列。listview视图显示详细信息 我已成功地将具有正确拆分的文件导入列表视图。我使用的代码是 使用sr作为StreamReader=File.OpenText(文件路径) 而(-1

所以我有一个listview,它有两列。listview视图显示详细信息

我已成功地将具有正确拆分的文件导入列表视图。我使用的代码是

使用sr作为StreamReader=File.OpenText(文件路径)
而(-1

因此,这会将我的文件中的行导入到正确的列中,并使用:as split。 现在我也有了一个选项,用户可以通过同样的方式将数据从我的程序添加到文件中,我使用了这段代码

     Using sw As StreamWriter = File.AppendText(file path)
    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
摘自: 但是我的错,vb给出了这个错误

错误1表达式的类型为“System.Windows.Forms.ListView”,它不是集合类型。C:\Users\xxxx\documents\visual studio 2012\xxxxx\Form1.vb 97

我不确定为什么会出现此错误,是因为我的列表视图属性吗

当用户单击按钮时,我希望能够将数据保存到文本文件中。

此行:

For Each item As ListViewItem in ListView1
应该是这样的:

For Each item As ListViewItem in ListView1.Items
For Each entry As ListViewItem.ListViewSubItem in item.SubItems
这一行:

For Each entry As String in item.SubItems
应该是这样的:

For Each item As ListViewItem in ListView1.Items
For Each entry As ListViewItem.ListViewSubItem in item.SubItems

然后从子项的Text属性中获取字符串。

将每个条目作为项中的字符串。子项
错误-项包含子项的集合,因此您无法使用字符串变量对其进行迭代,将每个项作为listview1中的ListViewItem。项作为字符串变暗行=每个条目作为字符串均为零item.SubItems行中的ListViewItem.ListViewSubItem.Append(条目&“:”)下一个sw.WriteLine(行)下一个sw.Close()结束,但我得到了line.Append的错误。错误1“Append”不是“String”101的成员错误2运算符“&”未为“System.Windows.Forms.ListViewItem.ListViewSubItem”和“String”类型定义。101我是否应该对变量行进行任何更改?您应该进行的更改是阅读我发布的内容并按照提供的说明进行操作。我特别声明,您可以从子项的Text属性获取字符串。你到底在干什么?谢谢你的帮助。I juz使用了反向方法,将文本保存到文件并更新listview。