移动到多选列表框的位置

问题描述 投票:0回答:1

我有一个多选列表框,我想使其可搜索。如果在列表框中找到搜索到的值,我想滚动到该位置,但不选择它。这可能吗?我到目前为止搜索的代码是: -

With lstComm
    For i = 0 To .ListCount - 1
        If .Column(6, i) = txtSearch.Value Then

        End If
    Next i
End With

...但我不知道如何完成滚动。

vba ms-access access-vba
1个回答
1
投票

这应该工作正常:

Dim index As Long
With lstComm
    Dim match As Boolean
    For index = 0 To .ListCount - 1
        If .Column(1, index) = txtSearch.Value Then
            match = True
            Exit For
        End If
    Next

    If Not match Then Exit Sub

    Dim isSelected As Boolean
    isSelected = .Selected(index)

    .Selected(index) = True
    .Selected(index) = isSelected
End With

它检索列表框的搜索项。

如果没有找到任何项目,则存在。

否则,它存储该项目的当前选择状态,选择它以定位列表框,并恢复项目的存储状态。

© www.soinside.com 2019 - 2024. All rights reserved.