Results 1 to 1 of 1

Thread: myDataGridView.DoubleBuffered(true)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    myDataGridView.DoubleBuffered(true)

    I know - there's no such function. let me explain. (Sorry about the long post - please do read on - I hope you'll find it interesting)

    I have a Sony Vaio. Not a portable - it's an 'all in one' computer. 22" display with the CPU, drives etc all built in to the display.

    Anyway - if I populate a datagridview with data and then do anything such as resize the window you can see the graphics redraw the data in the grid top to bottom. For example pull the window down to expose a couple more rows in the grid and it redraws the whole thing "s l o w l y". I noticed this about a year ago on my Sony but it never affected any other computers.

    I can avoid the problem by doing this:-


    public static class ExtensionMethods
    {
    public static void DoubleBuffered(this DataGridView dgv, bool setting)
    {
    typeof(DataGridView).InvokeMember( "DoubleBuffered", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, dgv, new object[] { setting });

    }
    }

    namespace System.Runtime.CompilerServices
    {
    public class ExtensionAttribute : Attribute { }
    }
    and then in the form load event I do this:-

    myDataGridView.DoubleBuffered(true);
    and that fixes the problem.

    I did that over a year ago and it's been working without any problems. The reason I mentioned this now is that a user contacted me today telling me about some 'other' strange behavior/distortion of datagridviews on some grids where I did NOT use the double buffered thing. All the data was there but the grid lines and 3D border etc were missing showing the data of underlying controls where the border and lines should be. As if the border and line color were transparent. Really strange.

    But that problem never affected the grids where I'd used the DoubleBuffered thing.

    I'm now going to go through my application using the doublebuffered on all of my grids

    BTW - there's 100's of users using this application an non of them have ever mentioned any such problem - only me with my sony (strange redrawing thing) and this one other user today (Strange transparent border and lines) In both cases it seems that setting the double buffered thing fixes it. Has anyone else ever noticed any (other) type of drawing problems of datagridviews ?
    Last edited by IanS; Aug 22nd, 2012 at 12:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width