Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to make DataGridView scrolling smooth (flickers problem)?

How to make DataGridView scrolling smooth (flickers problem)?

Scheduled Pinned Locked Moved C#
helpdatabasetutorialquestion
7 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Dunlop
    wrote on last edited by
    #1

    I have a DataGridView in my project which loads hundreds of rows from SQL CE file. It contains colorful texts and comboboxes. I searched online and found some solutions. Many of them says that I need to use double buffer. One of those solutions was this:

    public static class ExtensionMethods
    {
    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);
    }
    }

    and:

    this.dataGridView1.DoubleBuffered(true);

    I use following reference:

    using System.Reflection;

    My problem is that: 1) DataGridView in above class gives CS0118 error (has red underline) 2) Where should I use

    this.dataGridView1.DoubleBuffered(true);

    ?

    M 2 Replies Last reply
    0
    • A Alex Dunlop

      I have a DataGridView in my project which loads hundreds of rows from SQL CE file. It contains colorful texts and comboboxes. I searched online and found some solutions. Many of them says that I need to use double buffer. One of those solutions was this:

      public static class ExtensionMethods
      {
      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);
      }
      }

      and:

      this.dataGridView1.DoubleBuffered(true);

      I use following reference:

      using System.Reflection;

      My problem is that: 1) DataGridView in above class gives CS0118 error (has red underline) 2) Where should I use

      this.dataGridView1.DoubleBuffered(true);

      ?

      M Offline
      M Offline
      Maciej Los
      wrote on last edited by
      #2

      Take a look at this article [Double Buffering a DataGridview](https://www.codeproject.com/Tips/654101/Double-Buffering-a-DataGridview) to find out out how to enable DoubleBuffered.

      A 1 Reply Last reply
      0
      • M Maciej Los

        Take a look at this article [Double Buffering a DataGridview](https://www.codeproject.com/Tips/654101/Double-Buffering-a-DataGridview) to find out out how to enable DoubleBuffered.

        A Offline
        A Offline
        Alex Dunlop
        wrote on last edited by
        #3

        I pasted this code at the end of my code lines but IDE gives error.

        public partial class myDataGridView : DataGridView
        {
        public myDataGridView()
        {
        InitializeComponent();
        DoubleBuffered = true;
        }
        }

        The CS0118 eror code for DataGridView The CS0103 for InitializeComponent and DoubleBuffered How can I solve the problem? :confused:

        M 1 Reply Last reply
        0
        • A Alex Dunlop

          I pasted this code at the end of my code lines but IDE gives error.

          public partial class myDataGridView : DataGridView
          {
          public myDataGridView()
          {
          InitializeComponent();
          DoubleBuffered = true;
          }
          }

          The CS0118 eror code for DataGridView The CS0103 for InitializeComponent and DoubleBuffered How can I solve the problem? :confused:

          M Offline
          M Offline
          Maciej Los
          wrote on last edited by
          #4

          Based on this piece of code you provided, i can't tell you what is wrong. If you replaced your DataGridView control with myDataGridView, you should be able to use DoubleBuffered. An alternative... [How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls - Windows Forms .NET Framework | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-reduce-graphics-flicker-with-double-buffering-for-forms-and-controls?view=netframeworkdesktop-4.8) [Control.SetStyle(ControlStyles, Boolean) Method (System.Windows.Forms) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.setstyle?view=net-5.0)

          A 1 Reply Last reply
          0
          • M Maciej Los

            Based on this piece of code you provided, i can't tell you what is wrong. If you replaced your DataGridView control with myDataGridView, you should be able to use DoubleBuffered. An alternative... [How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls - Windows Forms .NET Framework | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-reduce-graphics-flicker-with-double-buffering-for-forms-and-controls?view=netframeworkdesktop-4.8) [Control.SetStyle(ControlStyles, Boolean) Method (System.Windows.Forms) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.setstyle?view=net-5.0)

            A Offline
            A Offline
            Alex Dunlop
            wrote on last edited by
            #5

            I provided an screenshot: Untitled — ImgBB[^]

            M 1 Reply Last reply
            0
            • A Alex Dunlop

              I provided an screenshot: Untitled — ImgBB[^]

              M Offline
              M Offline
              Maciej Los
              wrote on last edited by
              #6

              Seems, you don't understand what this code is doing... Please, read about [Inheritance - C# Programming Guide | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/inheritance) and [Polymorphism - C# Programming Guide | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/polymorphism) Tip: Go to the designer of Main class. Find 2 lines of declaration of dataGridView1:

              this.dataGridView1 = new DataGridView();
              //and
              private DataGridView dataGridView1;

              Above code means that you've created an instance of standard DataGridView. But(!) you need to create an instance od myDataGridView!

              this.dataGridView1 = new myDataGridView();
              //and
              private myDataGridView dataGridView1;

              For further details, please see: [Inherit from Existing Controls - Windows Forms .NET Framework | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-inherit-from-existing-windows-forms-controls?view=netframeworkdesktop-4.8) Good luck!

              1 Reply Last reply
              0
              • A Alex Dunlop

                I have a DataGridView in my project which loads hundreds of rows from SQL CE file. It contains colorful texts and comboboxes. I searched online and found some solutions. Many of them says that I need to use double buffer. One of those solutions was this:

                public static class ExtensionMethods
                {
                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);
                }
                }

                and:

                this.dataGridView1.DoubleBuffered(true);

                I use following reference:

                using System.Reflection;

                My problem is that: 1) DataGridView in above class gives CS0118 error (has red underline) 2) Where should I use

                this.dataGridView1.DoubleBuffered(true);

                ?

                M Offline
                M Offline
                Maciej Los
                wrote on last edited by
                #7

                If you would like to get "working" doublebuffered datagridview component, you can download necessary files from this repository: [GitHub - losmac/DoubleBufferedDataGridView: DataGridView (DoubleBuffered = true)](https://github.com/losmac/DoubleBufferedDataGridView) Good luck!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups