如何修复无法将最后一个元素滚动到视图中的 Excel 列表框 [英] How to fix an Excel listbox that can't scroll the last element into view

查看:27
本文介绍了如何修复无法将最后一个元素滚动到视图中的 Excel 列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我记事以来,我在 excel UI 中遇到的一个致命问题就是列表框滚动.

A killer problem I've had in excel UIs since as long as I can remember, is with listbox scrolling.

当列表框中有更多可以显示的元素时,会出现一个 scoll 条.但是,在某些情况下,将栏一直滚动到列表底部并释放它,会使栏向上跳"一个档次,您将无法看到列表中的最后一项.这在此处进行了说明:

When you have more elements in a listbox that can be displayed, a scoll bar will appear. In certain conditions, however, scrolling the bar all the way to the bottom of the list and releasing it, will "jump" the bar a notch upwards, and you won't be able to see the last item in the list. This is illustrated here:

有很多论坛帖子都提出了这个问题,解决方法一直是将积分高度属性设置为false,然后再将其设置为true".这样做是稍微调整列表框的大小,使其高度四舍五入到单行的高度,然后不会隐藏任何项目.

There are many forum posts presenting this issue, and the solution has always been "Set the integral height property to false, and then set it to true again." What this does is slightly resize the listbox so that it the height is rounded to the height of a single row, and then no items are left hidden.

With lstbox
    .IntegralHeight = False
    .Height = myHeight
    .IntegralHeight = True
End With

但是,在某些情况下,这不起作用.如果你是:

There are certain cases, however, where this does not work. If you are:

  1. 以编程方式设置列表框的高度
  2. 使用简单的列表框选择 (fmMultiSelectSingle)
  1. Programatically setting the height of your listbox
  2. NOT using simple listbox selection (fmMultiSelectSingle)

然后简单地将整数高度设置为 false ,然后在更改高度之后或之间设置为 true 将调整列表框的高度,但是当您向下滚动时,问题仍然存在 - 看不到最后一项.

Then simply setting integral height to false and then true after or between changes to height will make an adjustment to the height of your listbox, but when you go to scroll down, the problem will remain - the last item cannot be seen.

这个令人沮丧的问题的关键在于,虽然互联网上的其他所有人都在确认integralHeight"解决方案对他们有效,但这些非常特殊的情况却很沮丧,想知道为什么它对他们不起作用.那么他们如何解决问题呢?

The key to this frustrating question is that while everyone else on the internet is confirming that the 'integralHeight' solution works for them, these very special cases are frustrated wondering why it doesn't work for them. So how do they get their fix?

推荐答案

我必须自己发现的东西,并且在其他任何地方都找不到(这就是我在这里发布它的原因),是这个问题有增加了依赖于选择方法的维度.虽然我无法理解滚动条的工作方式不仅与高度和积分高度属性有关,还与 .MultiSelect 属性有关,但我发现确实如此.

Something I had to discover for myself, and which cannot be found anywhere else (which is why I'm posting it here), is that this problem had the added dimension of being dependent on the selection method. While I cannot fathom how the way the scroll bar works is related to not only the height and integral height property, but also the .MultiSelect property, I have found that it is.

当上面显示的 .IntegralHeight 方法不起作用时,以下方法会以某种方式起作用:

When the .IntegralHeight method shown above does not work, the following method somehow does:

With lstbox
    .IntegralHeight = False
    .Height = myHeight
    .IntegralHeight = True
    .MultiSelect = fmMultiSelectSingle
    .MultiSelect = fmMultiSelectExtended
End With

只需将 .MultiSelect 属性更改为 fmMultiSelectSingle,然后将其恢复为所需的选择样式,列表框的高度将由 .IntegralHeight 属性自动调整为与不执行这些操作时稍有不同的高度执行 - 差异导致滚动条正常工作:

By simply changing the .MultiSelect property to fmMultiSelectSingle, and then restoring it back to the selection style desired, the height of the listbox will be automatically adjusted by the .IntegralHeight property to a slightly different height than when these actions aren't performed - the difference results in the scroll bar working correctly:

我希望这种特殊情况的发现和更精确的解决方法可以帮助人们节省我必须经历的数小时的挫败感和实验.

I hope the discovery of this special case and more precise workaround saves someone the hours of frustration and experimentation I had to go through.

这篇关于如何修复无法将最后一个元素滚动到视图中的 Excel 列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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