当数据附加到文件时更新列表视图?
这就是我正在做的事情: 我正在将消息和日期时间记录到我成功完成的文本文件中。现在我想将相同的内容添加到列表视图(或可用于实现此目的的任何其他控件),并且当文件更新时,列表视图也应该更新。
我是 C# 新手,请原谅我缺乏知识。
Here's what I am doing:
I am logging messages and date time to a text file which I did successfully. Now I want to add the same to a Listview (or any other control which can be used to achieve this), also as and when the file is updated the Listview should be updated.
I am new to c# so excuse my lack of knowledge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 FileSystemWatcher
实例化 FileSystemWatcher:
设置通知过滤器: 应观察哪些事件
指定 FileWatcher 可以引发事件:
为该文件夹中的所有文件的更改事件添加事件处理程序:
捕获更改事件:
You can use FileSystemWatcher
Instantiate an FileSystemWatcher :
Set the notify filter : what events should be observed
Specify that the FileWatcher can raise events :
Add event handler for the change event for all files from that folder :
Capture the change event :
我假设您保存了在代码中所做的更改
,那么您需要观察文件何时发生更改,
当发生更改时,您需要自己获取更改
并将其添加到您想要的控件中,
例如,您可以在更改之前获取文件内容并存储它
然后在发生变化后获取它并进行比较
希望我有所帮助
I presume that you save the changes you made in your code
then you will need to watch when the changes happens to the file
when changes occurs you will need to get the changes on your own
and add it to the control you want
you can for example get the file content before changing and store it
then get it after change occurs and compare it
hope i helped