, :
DoubleBuffer DataGridView true. DataGridView, . , , .
class CustomDataGridView: DataGridView
{
public CustomDataGridView()
{
DoubleBuffered = true;
}
}
, DataGridView , , .
, - Win32 WM_SETREDRAW
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(HandleRef hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
static void EnableRepaint(HandleRef handle, bool enable)
{
const int WM_SETREDRAW = 0x000B;
SendMessage(handle, WM_SETREDRAW, new IntPtr(enable ? 1 : 0), IntPtr.Zero);
}
HandleRef gh = new HandleRef(this.Grid, this.Grid.Handle);
EnableRepaint(gh, false);
try
{
this.doStuff();
this.doOtherStuff();
this.doSomeReallyCoolStuff();
}
finally
{
EnableRepaint(gh, true);
this.Grid.Invalidate();
}