c# - Slow scroll on Winforms DataGridView -
i using datagridview
, scrolling behavior bad. works when scrolling moving scrollbar on side, extremely slow , freezes ui several seconds when fast scrolling mouse.
existing questions found suggest setting doublebuffered
property doesn't affect performance in case drawing fast when move scrollbar manually. problem scrolling mouse wheel.
solution handle wndproc
of mouse wheel event before control has chance handle , change firstdisplayedscrollingrowindex
property.
public class fastscrollingdatagridview : datagridview { private int numberofrowsperscroll = 20; short get_wheel_delta_wparam(intptr wparam) { var int32 = (int)wparam.toint64(); var shifted = int32 >> 16; return (short)shifted; } protected override void wndproc(ref message m) { if (m.msg == 0x20a) //wm_mousewheel = 0x20a { var zdelta = get_wheel_delta_wparam(m.wparam) > 0 ? numberofrowsperscroll : -numberofrowsperscroll; var newvalue = firstdisplayedscrollingrowindex - zdelta; if (newvalue < 0) newvalue = 0; this.firstdisplayedscrollingrowindex = newvalue; return; } base.wndproc(ref m); } }
Comments
Post a Comment