I have a lot of results displayed in DataGridView (rows and columns). When I scroll up and down or left and right the datagridview is refreshing and the cells are displayed each time. This is annoying because of refreshing and in specially when you have some operations in DataGridViewControl_CellFormatting
event.
How can I stop refreshing when I'm scrolling in dataGridView?
I'm using WinForms in C#
Asked
Active
Viewed 1,274 times
0

Ștefan Blaga
- 404
- 1
- 5
- 22
-
I filled a datagridview with 2000 items to test this for you but I'm having trouble reproducing your issue. With refresh I take it you mean its flickering? Have you tried dubblebuffered? I have posted an answer including that. – EpicKip Jan 12 '17 at 15:48
-
Yes, that's what I mean. Every time I scroll into datagridview the grid is flickering – Ștefan Blaga Jan 12 '17 at 16:13
1 Answers
2
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);
}
This is to enable doublebuffered on a Data grid view. I got this from SO
-
Good find, although I would agree with cody: _The method you posted uses reflection to change a non-public property on a DataGridView control. This is an acceptable solution, but it's probably cleaner just to inherit off of the existing DataGridView control and create your own custom control with the "DoubleBuffered" style set._ – TaW Jan 12 '17 at 16:39