Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to scroll a DataGridView?

Posted on 2006-07-05
4
Medium Priority
?
4,601 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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