How to make DataGridView scrolling smooth (flickers problem)?
-
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);
?
-
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);
?
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
. -
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
.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:
-
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:
Based on this piece of code you provided, i can't tell you what is wrong. If you replaced your
DataGridView
control withmyDataGridView
, you should be able to useDoubleBuffered
. 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) -
Based on this piece of code you provided, i can't tell you what is wrong. If you replaced your
DataGridView
control withmyDataGridView
, you should be able to useDoubleBuffered
. 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)I provided an screenshot: Untitled — ImgBB[^]
-
I provided an screenshot: Untitled — ImgBB[^]
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 ofdataGridView1
: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 odmyDataGridView
!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!
-
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);
?
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!