当调用列表框时,将执行以下例程.它会检查文本文件是否存在,如果存在,则从文件中读取每一行并将其添加到列表框中.
The following routine executes when a listbox is called. It checks if a text file exists, and if it does, then it reads each line from the file and adds them tothe listbox.
我遇到的问题是,如果我第二次打开列表框,则没有从文件中读取任何行.
The problem I'm having is if I open the listbox a second time,no lines are being read from the file.
这是因为文件位置在文件末尾吗?如果是,该如何倒带?
Is this because the file position is end-of-file? If so, how can I rewind it?
公共类Dialog_ListLoads 私有子对话框Dialog_ListLoads_Load(发送为System.Object,发送为System.EventArgs)处理MyBase.Load 暗淡的lines()作为字符串 昏暗的fname作为字符串
Public Class Dialog_ListLoads Private Sub Dialog_ListLoads_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim lines() As String Dim fname As String
ListBox1.Items.Clear() fname = ShaftAnalysis_Home& " \ 57_Load_List.txt"
ListBox1.Items.Clear() fname = ShaftAnalysis_Home & "\57_Load_List.txt"
如果System.IO.File.Exists(fname)= True,那么 行数= File.ReadAllLines(fname)
If System.IO.File.Exists(fname) = True Then lines = File.ReadAllLines(fname)
对于i As Integer = 0到lines.Count-1 ListBox1.Items.Add(lines(i)) 下一个 如果结束 结束子 结束班
For i As Integer = 0 To lines.Count - 1 ListBox1.Items.Add(lines(i)) Next End If End Sub End Class
迈克
推荐答案
迈克,你好
我认为与Visual Basic Windows窗体的静态行为有关.
I assume that it is more to do with the static behaviour of a Visual Basic Windows Forms.
那么更重要的是,您如何称呼该表格,然后可能有很多原因,您可以向我们展示一下吗?
More important is then how you call that form and then there can be many reasons, can you show that to us.
更多推荐
是否需要倒带ReadAllLines文件?
发布评论