Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Showing data in my form (http://www.go4expert.com/forums/data-form-t12069/)

pb_ce85 13Jul2008 09:55

Showing data in my form
 
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! it is highly slow and can change that "less than a second" to about twenty seconds!!! I'm searching for fastest way to show these data in my form. Thanks a lot for your helping.
My code's like this:

Code:

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 */));
}

I examined this code too but nothing changed!

Code:

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!!!
}



All times are GMT +5.5. The time now is 17:01.