如何以像素为单位滚动DataGridView [英] How to scroll DataGridView in pixel increments

查看:289
本文介绍了如何以像素为单位滚动DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的原始方法是将DataGridView放在面板中,将其高度设置在面板边界之外,然后更改控制面板的滚动条位置。但是,我刚刚发现,我的DataGridView中的行数将达到2000,这迫使我将DataGridView的大小至少为:


65px(行高)x 2,000 = 130,000px。


我的64位机器上的DataGridView控件允许的最大大小为65,535。任何人都可以想办法解决这个问题?

解决方案

嗯,不,你不能这样做。 65535像素的大小限制并不是人为的,操作系统是一个严酷的限制。基本原因是 WM_VSCROLL消息。通过的LPARAM参数的值被记录为:


如果LOWORD为SB_THUMBPOSITION或SB_THUMBTRACK,HIWORD指定滚动框的当前位置


HIWORD是值中的高16位,LOWORD是低16位。其中只能提供范围为0 .. Pow(2,16)-1 = 0..65535。这个限制在其他地方是可见的,如果你使用超过(65535 +可见)项目的东西,ListBox的行为不正确。您不能滚动到底部。



听起来像一个非常棘手的问题,当然,微软应该在他们的软件中修复这样可怕的限制。但不,这不是他们的优先级列表。与WaitHandle.WaitAny()无法处理包含超过64个项目的数组的看似奇怪的限制不同。这是有意的,他们认为你正在做错,而不是他们。而且,您是一个用户界面,期望用户必须通过数千行信息来获取不是非常有用或友好的界面。从Google,显示数十万个查询匹配的方式来提示。


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?

解决方案

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:

The HIWORD specifies the current position of the scroll box if the LOWORD is SB_THUMBPOSITION or SB_THUMBTRACK

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.

这篇关于如何以像素为单位滚动DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆