How to scroll a DataGridView?
Posted on 2006-07-05
DataGridView has HorizontalScrollBar and VerticalScrollBar properties, but they are protected. It also has a public read/write HorizontalScrollingOffset property, which works great at programaticaly scrolling the DataGridView horizontally. The VerticalScrollingOffset property, however, is read only. I need a way to scroll DataGridView vertically or horizontally x amount of pixels programatically. I tried to SendMessage WM_VSCROLL to the control, but that did not do anything.
private int WM_VSCROLL = 0x0115;
private int SB_PAGEDOWN = 3;
private int SB_LINEDOWN = 1;
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
Try to scroll:
SendMessage(this.dataGridView1.Handle, WM_VSCROLL, (IntPtr)SB_PAGEDOWN, IntPtr.Zero);