ListBox 表单控件滚动 [英] ListBox Form Control Scrolling

查看:48
本文介绍了ListBox 表单控件滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做大量的研究,我终于屈服了,希望社区能提供帮助.我有一个 FORM CONTROL 列表框,而不是一个活动的 x.我出于各种不一定重要的原因有意使用表单控件(除非您可以指导我如何 100% 确保 ActiveX 控件不会在打开工作簿时调整自身大小).我一生都无法弄清楚如何让表单控件列表框滚动到选定的值并将其置于视图中.这是我所拥有的:

I've been doing a ton of research and I'm finally giving in and hoping the community can help. I have a FORM CONTROL list box, not an active x. I'm intentionally using form control for a variety of reasons that are not necessarily important (unless you can guide me how to 100% ensure activeX controls don't resize themselves on workbook open). I cannot, for the life of me, figure out how to get the form control list box to scroll to the selected value and put it in view. Here is what I have:

ActiveSheet.ListBoxes("List Box 13").Selected = 100

该列表中有 1000 个可供选择的值.当它运行时,#100 被选中,但不在视图中.列表框不会移动.

The list has 1000 values in it to be selected. When this runs, #100 is selected, but is not in view. The list box does not move.

我怎样才能让选中的值出现在顶部?

ActiveX 将是:

ActiveX would be:

.TopIndex

但这不适用于表单控件.

But that is not available for form controls.

推荐答案

滚动到给定的列表框索引以显示在可见列表的顶部

我一生都无法弄清楚如何让表单控件列表框滚动到所选值并将其置于视图中.

似乎实际上没有标准方法(除了 API 调用)来控制 表单 控件列表框而不是 用户表单 的列表框内部显示的可见性的 ActiveX 控件列表框.

Seems that actually there's no standard method (leaving aside API calls) to control the visibility of the listbox interior display for a form control list box as opposed to a Userform's ActiveX control list box.

其他提示

为了完整起见(并且由于评论),我演示了如何通过组合两个导航属性来滚动到用户窗体列表框中的视图 - 即通过设置 .ListIndex以及 .TopIndex 以及定义的索引 value :-),例如通过如下程序:

For the sake of completeness (and due to comment) I demonstrate how to scroll into view in a Userform's listbox by combining both navigation properties - i.e. by setting .ListIndex as well as .TopIndex together with a defined index value :-), e.g. via a procedure as follows:

示例调用

  ScrollTo 100          ' attention: zerobased

  ScrollTo ActiveSheet.ListBoxes("List Box 13").Selected 

辅助程序

... 将当前的 ListIndex 设置为例如100 AND 将其定义为 .TopIndex.

... sets the current ListIndex to e.g. 100 AND defines it as .TopIndex.

(旁注:当然,列表末尾的目标甚至可以显示在 .TopIndex 下方,具体取决于实际的 .ListCount)

(Side note: of course targets at the very list end could be displayed even below .TopIndex depending on the actual .ListCount)

Private Sub ScrollTo(ByVal idx&)
' Purpose: Scroll to given target index to be displayed on top of visible list
' Site:    https://stackoverflow.com/questions/56813550/listbox-form-control-scrolling 
' Author:  https://stackoverflow.com/users/6460297/t-m
    Me.ListBox1.TopIndex = idx
    Me.ListBox1.ListIndex = idx
End Sub

这篇关于ListBox 表单控件滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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