Solved

How to scroll a DataGridView?

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now