mrdutchie Posted February 5, 2004 Posted February 5, 2004 Hi, I am trying to read a Textfile with 40.000 lines into a listbox so I am reading each line and add it to the listbox, but that takes about 15-20 seconds... way to slow :( Isn't there a faster way to do it? Cause I found a routine that only takes 4-8 seconds but that reads it into a Datagrid and that's not what I want. Quote
*Experts* Bucky Posted February 5, 2004 *Experts* Posted February 5, 2004 Don't use the ReadLine or ReadToEnd methods of the reader. Instead, get the Length of stream, then Read() the entire thing into a Byte array, and then convert it to a string using System.Text.Encoding.[whatever encoding].GetString(). Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
mrdutchie Posted February 5, 2004 Author Posted February 5, 2004 Thanks, I will look into that again. I remember trying that once before and never got it to work :( Quote
mrdutchie Posted February 5, 2004 Author Posted February 5, 2004 OK, I have this now and it reads it very fast into s(0) but still adding to the listviewer takes forever. Dim s As Array Dim w As String Dim f As String = "C:\newsgroups.txt" Dim stream_reader As New IO.StreamReader(f) s = (Split(stream_reader.ReadToEnd, vbCrLf)) stream_reader.Close() ' MsgBox("done") This takes only 1 second and ' all the data is in s(0) Dim a() As String = s(0).Split(Chr(10)) For x = 1 To a.Length - 1 ListView1.Items.Add(a(x)) Next What am I missing here? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.