Solved

How to scroll a DataGridView?

Posted on 2006-07-05
4
4,515 Views
Last Modified: 2012-05-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.

Example:

private int WM_VSCROLL = 0x0115;
private int SB_PAGEDOWN = 3;
private int SB_LINEDOWN = 1;
       
[DllImport("user32")]
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);


Please help.
0
Comment
Question by:krupini
  • 2
4 Comments
 

Author Comment

by:krupini
ID: 17043295
The above code, for example, works for a TextBox control ...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17046823
Here is a thought:

using System.Reflection;

...


PropertyInfo verticalOffset = this.dataGridView1.GetType.GetProperty("VerticalOffset", BindingFlags.NonPublic | BindingFlags.Instance);

// Set the scroll offset to 10.
verticalOffset.SetValue(this.dataGridView1, 10, null)

Bob
0
 
LVL 5

Accepted Solution

by:
nickhoggard earned 500 total points
ID: 17048862
Hi,

This is not pixel based, so I'm not sure that it will help you, but the FirstDisplayedScrollingRowIndex property on the DataGridView has usually done everything I've needed for setting the scrolled location.

Hope this helps

Nick
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17050234
Thanks, Nick, there are so many properties and so little time to discover them all.

Bob
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question