Jump to content

"Read from file" problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
pb_ce85

pb_ce85

    Newbie

  • Members
  • PipPip
  • 21 posts
Hi!
I am using the BinaryReader class in System.IO namespace (in C# of course) for reading data from a file. It's very fast (can read 1,000,000 bytes in less than a second) but I'm using a DataGridView control to show them in my form and (as you may know) it is very absurd!:irritated: it is highly slow and can change that "less than a second" to about twenty seconds!!!:loading: I'm searching for fastest way to show these informations in my form. Thanks a lot for your helping.
My code's like this:

using System.IO;

void Fill_DataGridView1_using_BinaryReader(string path)
{
BinaryReader br = new BinaryReader(path);

for (int i = 0; i < length(path); i++)
DataGridView1.Rows.Add(br.ReadChars(10 /* for example */));
}

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You could read the data into a variable first, and then unpack it into the DataGridView.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
pb_ce85

pb_ce85

    Newbie

  • Members
  • PipPip
  • 21 posts
Thanks Xav.
I examined the code below but unfortunately didn't work. Loading data is not my problem, Showing them in a DataGridView control reduces my speed.


using System.IO;

void Fill_DataGridView1_using_BinaryReader_#2(string path)

{

   BinaryReader br = new BinaryReader(path);

   List<string> data = new List<string>();

   

   for (int i = 0; i <= length(path); i++)

      data.Add(br.ReadChar());

   // 0.4 seconds passed

   for (int i = 0; i < data.Length; i++)

      DataGridView1.Rows.Add(data[i]);

   // 20.4 seconds passed!!!

}



#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I suppose it doesn't matter about speed too much, though? Just include an Application.DoEvents() in the loop, and it should be responsive enough.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums