Текстовое поле UserForm медленно и не показывает символы как напечатанные - PullRequest
0 голосов
/ 11 апреля 2019

Я пытаюсь получить список в пользовательской форме для динамической фильтрации содержимого по тому, что введено в текстовое поле в той же форме. Это работает, но когда пользователь начинает печатать, он в основном зависает при выполнении кода для фильтрации. Если я наберу серию символов быстро, текстовое поле не будет отображать символы в течение нескольких секунд. Я хотел бы динамически фильтровать список без задержки.

Я пытался создать таймер, который бы умножил время, прошедшее с того момента, когда пользователь последний раз вводил символ перед выполнением фильтра, но это принесло с собой еще один набор проблем, включая последний символ, который пользователь вводит, не запуская textbox_change если оно было напечатано быстро по отношению к предпоследнему символу.

Private Sub FilterTextBox_Change()

Dim bSelected As Boolean
Dim lListIncrementer As Long
Dim lDictionaryIncrementer As Long
Dim lOriginalListBoxDictionaryIncrementer As Long
Dim lLastListItem As Long
Dim sFilterString As String
Dim lDictionaryIncrementerOffset As Long
Dim dTimerDifference As Double
Dim sCurrentString As String

sFilterString = UCase(InvoiceProductAssociation.FilterTextBox.Text)
lLastListItem = InvoiceProductAssociation.CatapultItemIdAndDescriptionListBox.ListCount - 1
lDictionaryIncrementerOffset = 0


For lDictionaryIncrementer = 0 To oListBoxItemDictionary.Count - 1
    sCurrentString = UCase(oListBoxItemDictionary.Keys(lDictionaryIncrementer))

    If InStr(sCurrentString, sFilterString) Then
        oListBoxItemDictionary(oListBoxItemDictionary.Keys(lDictionaryIncrementer)) = "Show"
    ElseIf sFilterString = vbNullString Then
        oListBoxItemDictionary(oListBoxItemDictionary.Keys(lDictionaryIncrementer)) = "Show"
    Else
        oListBoxItemDictionary(oListBoxItemDictionary.Keys(lDictionaryIncrementer)) = "Hide"
    End If
Next lDictionaryIncrementer

For lListIncrementer = 0 To lLastListItem

    If InvoiceProductAssociation.CatapultItemIdAndDescriptionListBox.Selected(lListIncrementer) = True Then
        oListBoxSelectedDictionary("Selected") = InvoiceProductAssociation.CatapultItemIdAndDescriptionListBox.List(lListIncrementer)
    End If

Next lListIncrementer

InvoiceProductAssociation.CatapultItemIdAndDescriptionListBox.Clear

For lDictionaryIncrementer = 0 To oListBoxItemDictionary.Count - 1

    If oListBoxItemDictionary.Items(lDictionaryIncrementer) = "Show" Then

        With InvoiceProductAssociation.CatapultItemIdAndDescriptionListBox
            .AddItem oListBoxItemDictionary.Keys(lDictionaryIncrementer)
            If oListBoxSelectedDictionary("Selected") = oListBoxItemDictionary.Keys(lDictionaryIncrementer) Then
                InvoiceProductAssociation.CatapultItemIdAndDescriptionListBox.Selected(lDictionaryIncrementer + lDictionaryIncrementerOffset) = True
            End If
        End With
    Else
        lDictionaryIncrementerOffset = lDictionaryIncrementerOffset - 1
    End If

    lListIncrementer = lListIncrementer + 1

Next lDictionaryIncrementer

End Sub

Количество элементов, загружаемых в словарь, превышает 1000, но словари были очень отзывчивы для меня в прошлом, поэтому я думаю, что .additem вызывает задержку.

Мне интересно, есть ли у кого-нибудь какие-либо предложения о том, как быстрее добавить элементы в список, или есть предложение об успешном запуске фильтра только после того, как пользователь перестал печатать в течение x секунд.

...