0

Just a simple question. I found how to speed up datagridview by enabling Double buffering hided feature. Is it fine if i place that code into Form's load event when datagridview is located?

typeof(DataGridView).InvokeMember(
                "DoubleBuffered",
                BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
                null,
                grid,
                new object[] { true });

Code taken from here

Arie
  • 3,041
  • 7
  • 32
  • 63
  • 3
    This should not matter at all; when set it'll stick until unset. – TaW Sep 01 '20 at 21:21
  • @TaW i assume this code has to be added to every form where datagridviews are used, am i right? – Arie Sep 01 '20 at 21:24
  • 1
    Either that or use a DGV subclass with DoubleBuffering enabled in its constructor(s).. Not that one always needs it, though: esp. with only a few rows/columns it is not necessary..But, [when](https://stackoverflow.com/questions/41893708/how-to-prevent-datagridview-from-flickering-when-scrolling-horizontally/41894210#41894210) you do it is nice – TaW Sep 01 '20 at 21:26
  • @TaW but how can i use that class: class DBDataGridView : DataGridView. I already has my datagridview on form. How to do that? – Arie Sep 01 '20 at 21:30
  • 1
    Well one can always edit the Designer.cs file __if__ one does it right. There are 2 (or 3?) spots in it where the control is defined as a DGV; change them to be you DBDGV class and all ought to be well. Make sure to properly backup before editing the desinger.cs file !!! – TaW Sep 01 '20 at 21:35
  • 1
    @TaW i put that peace of code to static method in external static class helper: public static void TurnOnDoubleBufferec(DataGridView grid) .. and call this static method from each form i need – Arie Sep 01 '20 at 21:37
  • 1
    Are you really speeding up, or just preventing code from hanging? What I usually do when I get a winform that hangs is put code into a backgroundworker so form doesn't lock up. Sounds like you have same issue with form locking. – jdweng Sep 01 '20 at 21:53
  • @jdw: This is really about scrolling large DGVs. You can see the effect in the link in my comment above.. – TaW Sep 02 '20 at 01:48

0 Answers0