How to fix an Excel listbox that can't scroll the last element into view

末鹿安然 提交于 2019-11-29 01:36:36

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.

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

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.

I had to anchor the position since my ListBox was walking across the page:

With ListBox1 
 .IntegralHeight = False
 .IntegralHeight = True
 .Height = 45
 .Width = 69
 .Top = 0
 .Left = 1255.5
End With

With lstbox

`.Height = myHeight`
`.MultiSelect = fmMultiSelectExtended`
`.MultiSelect = fmMultiSelectSingle`

End With

This worked for me. No need of setting Integral height property

In my case the solution was this method:

with listbox
   .IntegralHeight = False
   .Height = myHeight
   .Width = myWidth
   .IntegralHeight = True
   .Height = myHeight
   .Width = myWidth
end with

Enjoy.

found ridiculously simple way to resolve this issue. adjust your height up or down a little bit so bottom line of list box is between check boxes, then you can scroll down to last item even if IntegralHeight is set to false

Thanks Alain. Your fix worked well for me.

I found a subsequent problem related to the height of the ListBox when resized, that it varied in an unpredictable way depending on the initial height. The resized height was different again when displayed on another machine with 125% text scaling. For example, if I set a height between 358 and 370, the resized height is either 370.65 or 371.4 on my machine but on the machine with 125% text scaling, it is 360.1, 370.25 or 380.45. With such large variability, the result was that the ListBox could obscure other controls below it.

The fix was to start with the maximum height I wanted and reduce the initial height until the resized height was less than the maximum height I wanted. I do this whenever I display that ListBox.

    Hmax = 372      'Target Height 
    H1 = Hmax
    With SteelForm.Controls.Item("ListBox1")
        Do
            H1 = H1 - 1
            .IntegralHeight = False
            .Height = H1
            .IntegralHeight = True
            .MultiSelect = fmMultiSelectSingle
            .MultiSelect = fmMultiSelectExtended
            DoEvents
        Loop Until .Height < Hmax
    End With

i know this is very old post. but i've been through a lot to fix this problem, so i just wanna share my tip. :)

first of all, integralheight method doesn't work when worksheet zoom level is not 100%.

it will change listbox height and width, location, etc. (even if you set object property 'doesn't move or reseize with cell')

and when you try to take it its original size and location with code to fix this, this time its last item can't be seen

my tip is simple. there's combination between font size and listbox height.

if your font size is 6-10(arial, regular), listbox height goes well with multiples of 12.75 (btw my list box style is 1 : ListStyle, 1-fmListStyleOption. it could be different with style 0)

as long as height is same with these multiples of 12.75, there will be no problem.

in case of font size 12(arial, regular), it's multiples of 13.55

so if there's no restiction about listbox size in your project, just resizing it slightly depending on your font size gives more comfort. :)

What I've seen in the past on forums is just adding an extra blank row to your list box. That should do it.

sridevi

Just set the Integral Height property to True

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!