November 30, 2010

How to increase speed of DataGridView or using DoubleBuffered property...

A few days ago I finished developing the output window of results. It's a window similar to Visual Studio Output Window. It has a few tabs and one tab was very-very annoying. Why? Because it first performance was very low... This tab is responsible for showing all messages from external compiler what we use to compile some source. For the displaying compiler messages we used standard DataGridView component. I don't like it but his layout is that what I need. When we start our application to have real tests we were sadden. Blinking, flicker, pulling... It was the terrible to think that someone will use this dung... Google is power! But not in this situation. Every query doesn't get appropriate results. Search and search.. Nothing... Only similar troubles with no smart answers. You say I search bad.. Maybe, but in that day I don't think that. In that day power has a stackoverflow. :) Yes, yes, yes... Two minutes and I have a great answer.
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
    Type dgvType = dgv.GetType();
    PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
          BindingFlags.Instance | BindingFlags.NonPublic);
    pi.SetValue(dgv, setting, null);
}


Only one extension method to DataGridView and that's all. It's amazing..

Blinking, flicker, pulling.. No, no, no... Only smooth, clarity, speed... All what we need.

And only one question stay in my head. Why "DoubleBuffered" property is hidden? Maybe when whe set it to the true our application eats all RAM memory? Maybe our Duo Core Processors will work to the 100% to render data.. Hm.. Practical experience shown that with memory is all right (a little more, but a little) and with processor too.

MSDN says that this property indicating whether this control should redraw its surface using a secondary buffer to reduce or prevent flicker.

1 comment:

  1. -1
    down vote
    favorite


    I have a developed a small windows application with three tier Achr, it has just a datagridview to display records (Through Query i am pulling the data and display the 300 record, No Columns are define).

    I have set the Scroll property to Both of Datagrdiview.

    The problem is when i try to scroll the datagridview get slow and not working smoothly.

    i am facing this problem while draging scrollbar and using mouse scroll.

    i have googled through some site which suggest to increase the buffer memory so i set the doublebuffer = true but still i havent got the satisfactory results.

    Now i have tried almost everything but still my datagridview is not behaving normally when it comes to scrolling.

    Please suggest a way to get out of the issue!

    ReplyDelete