如何刷新文本文件以显示已删除行 [英] How do I refresh a textfile to show that a line has been deleted

查看:65
本文介绍了如何刷新文本文件以显示已删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文本文件已连接到已检查的列表框控件。我可以添加和删除里面的不同项目。问题是当我删除连接到Checkedlistbox的文本文件没有更新时,我必须退出并返回以查看我所做的更改。



这里是删除代码:



I have my text file connected to a checked listbox control. I can add and delete the different items that are inside. The problem is that when I delete the textfile connected to the Checkedlistbox does not update, I have to exit out and come back in to see the changes that I have made.

here is the delete code:

Dim List As New List(Of String)(File.ReadAllLines("Mytext"))

      For Each line In CheckedListBox1.CheckedItems

          'Remove the line to delete, e.g.
          List.Remove(line)

      Next

      File.WriteAllLines("Mytext", linesList.ToArray())





我需要帮助才能刷新数据



我尝试了什么:



我试图使用readalllines清除并重新读取数据。我还尝试在checkedlistbox上刷新和更新。



I need help with getting the data to refresh

What I have tried:

I have tried to do a clear and reread the data using the readalllines. I have also tried a refresh and update on the checkedlistbox.

推荐答案

你的代码没有按照你期望的方式行事,你不明白为什么!



有一个几乎通用的解决方案:逐步在调试器上运行代码,检查变量。

使用调试器查看代码在做什么。它允许你逐行执行第1行并在执行时检查变量,它是一个令人难以置信的学习工具。

调试器中没有魔法,它没有发现错误,它只是帮助你到。当代码没有达到预期的效果时,你就接近了一个bug。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio中的调试2010 - 初学者指南 [ ^ ]



此解决方案的缺点:

- 这是一个DIY,你是一个跟踪问题并找到根源,这将导致解决方案。

此解决方案的优点:

- 您看到您的代码行为,您将其与您的期望相匹配。



次要效果

- 你会为自己找到虫子感到骄傲。

- 哟你的技能会提高。



你应该很快就会发现错误。
Your code do not behave the way you expect, and you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The downside of this solution:
- It is a DIY, you are the one tracking the problem and finding its roots, which lead to the solution.
The upside of this solution:
- You see your code behaviour, you match it against your expectations.

secondary effects
- Your will be proud of finding bugs yourself.
- Your skills will improve.

You should find pretty quickly what is wrong.


你可以添加一个按钮来重新绑定更新的文本文件到checkedlistbox,例如
You can add a button to rebind the updated text file to the checkedlistbox, e.g.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  
        CheckedListBox1.Items.Clear()

        Using Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser("TextFile1.txt")

            Reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
            Reader.Delimiters = New String() {","}

            Dim Row As String()

            While Not Reader.EndOfData
                Row = Reader.ReadFields()
                CheckedListBox1.Items.Add(Row(1))
            End While

        End Using

End Sub


这篇关于如何刷新文本文件以显示已删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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