Showing data in my form

Discussion in 'C#' started by pb_ce85, Jul 13, 2008.

  1. pb_ce85

    pb_ce85 New Member

    Joined:
    Jul 13, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Iran
    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!!!
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice