Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to scroll a DataGridView?

Posted on 2006-07-05
4
Medium Priority
?
4,633 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

886 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