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

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

问题描述

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

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:

65 像素(行高)x 2,000 = 130,000 像素.

65px (row height) x 2,000 = 130,000px.

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

The maximum allowed size for a DataGridView control on my 64bit machine is 65,535. Anyone can think of a way around this issue?

推荐答案

嗯,不,你不能两全其美.65535 像素的大小限制不是人为的,它是操作系统中的硬限制.根本原因是 WM_VSCROLL 消息.传递的 LPARAM 参数的值记录为:

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:

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

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

HIWORD 是值的高 16 位,LOWORD 是低 16 位.其中只能提供 0 .. Pow(2, 16)-1 = 0..65535 的范围.这个限制在其他地方是可见的,如果你用超过(65535 + 可见)个项目来填充列表框,它就会表现得很糟糕.您无法再滚动到底部.

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.

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

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天全站免登陆