Solved

How to scroll a DataGridView?

Posted on 2006-07-05
4
4,561 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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

628 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