My original approach was to enclose my DataGridView inside a panel, set its height outside the boundary of the panel and then change control panel's scroll bar position. However, I just found out that the number of rows inside my DataGridView would reach 2000, which forces me to size the DataGridView to at least:
65px (row height) x 2,000 = 130,000px.
The maximum allowed size for a DataGridView control on my 64bit machine is 65,535. Anyone can think of a way around this issue?
Maybe you could set the row height to be something like 1 pixel so all rows become 1 pixel high at the moment it all loads in. Then assuming you know how many rows can be visible in the maximum height of the DataGridView that you have you could make sure 1 row is selected and gets placed in the center of it. Then with a loop you could set the height of the selected row and
x
rows above and below the selected row to the 65 pixels. And have when the selected row changes (when the user uses arrow keys etc) have it scroll the selected to the center and resize the rows again. That's the only way I can think of for this case.I hope that it is some help to you.
Hmm, no, you cannot have it both ways. The size restriction of 65535 pixels is not artificial, it is a hard-baked limitation in the operating system. The underlying reason is the WM_VSCROLL message. The value of the passed LPARAM argument is documented as:
HIWORD are the upper 16 bits in the value, LOWORD are the lower 16 bits. Which can only provide a range of 0 .. Pow(2, 16)-1 = 0..65535. This limitation is visible in other places, a ListBox misbehaves badly if you stuff it with more than (65535 + visible) items. You can't scroll to the bottom anymore.
Sounds like a pretty crummy problem, surely Microsoft ought to fix such horrid limitations in their software. But no, this is not on top of their priority list. Not unlike the seemingly strange limitation that WaitHandle.WaitAny() cannot deal with an array that contains more than 64 items. This is intentional, they think that you are doing it wrong, not them. And you are, a user interface that expects a user to have to claw through thousands of rows of information is not a very usable or friendly interface. Take a cue from, say, the way Google displays hundreds of thousands of query hits.
Take this code for example, the only property you have any control of is the FirstDisplayedScrollingRowIndex.
You cannot scroll a DataGridView row as a fraction (eg a half row scroll or... with more granularity down to the pixel level as you desire.)
You might need to resort to screenshots (ie using Blips) so you can trick the user into thinking the grid is scrolling one pixel at a time when really its just a image. I wouldn't recommend this approach.
The other way is using a ViewPort like a Panel or a GroupBox and changing the top position of the GridView.