0

我在 MS 访问表单 2010 上有一个多选列表框,我有一个例程选择这样的默认值

 For i = 0 To CategoriesList.ListCount - 1
If InStr(1, ",2,3,17,6,22,13,10,48,39,18,", ("," & CategoriesList.ItemData(i) & ",")) Then
CategoriesList.Selected(i) = True
End If
Next i

效果很好,现在问题是列表框只有三个项目的高度,总共有 48 个 iems,一旦我执行上述例程,列表框显示最后三个项目是默认的(滚动到底部)

如何让列表框默认滚动到顶部?

4

2 回答 2

1

为此,不必将焦点设置到列表框,反向循环遍历列表项。由于代码将在第一项结束,因此列表框将滚动到顶部:

    For i =  (CategoriesList.ListCount - 1) to 0 Step -1
    If InStr(1, ",2,3,17,6,22,13,10,48,39,18,", ("," & CategoriesList.ItemData(i) & ",")) Then
    CategoriesList.Selected(i) = True
    End If
    Next
于 2013-09-23T18:08:14.310 回答
0

You can do this by setting the ListIndex to 1 (the first item) but it requires the listbox to have focus:

Me.List6.Selected(8) = True
Me.List6.Selected(9) = True
Me.List6.SetFocus
Me.List6.ListIndex = 1

If you set the ListIndex to the first found item (i) then it will make this the top (displayed) item in the list.

于 2013-07-18T23:10:22.957 回答