文本更改属性上的选定索引值-性能受到影响



我正在制作windows应用程序表单,我有一个文本框和列表框。我想如果用户在文本框上键入,那么列表框项将被选中,这是工作良好。

列表框中有超过10,000条记录。

从列表框中选择项目需要时间,而在文本框中写入数据需要时间。

下面是我的代码:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If TextBox1.Text.Length > 0 Then
            Dim iSelectedInd As Int32
            iSelectedInd = lstParty.FindString(TextBox1.Text)
            If iSelectedInd >= 1 Then
                lstParty.SetSelected(iSelectedInd, True)
            End If
        End If
End Sub

如果包含一秒钟的延迟,它只会在用户停止输入时搜索列表。创建包含Interval = 1000Enabled = FalseTimer

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.TextChanged
    ' Reset the timer.
    Timer1.Enabled = False
    Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
    ' Stop the timer.
    Timer1.Enabled = False
    ' Search the list for the text.
    If TextBox1.Text.Length > 0 Then
        Dim iSelectedInd As Int32
        iSelectedInd = lstParty.FindString(TextBox1.Text)
        If iSelectedInd >= 1 Then
            lstParty.SetSelected(iSelectedInd, True)
        End If
    End If
End Sub

最新更新