1

I have auto complete functionality in combo box ,it works properly but there is little issue ,I made the suggestion list appear for the text length more than 3 chars ,but the list appears after the length of 4 char (when user enters the fifth char of the text) which means when the code executed in the first time the list doesn't appear here is the code in Text_Changed Event

 Private Sub TxtItem_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtItem.TextChanged


    If Trim(TxtItem.Text) <> "" And Trim(TxtItem.Text).Length > 3 Then
        'Autocomplete
        Dim Bl As New ItemBL
        Dim suggestions = Bl.DisplayLikeNameList(Trim(TxtItem.Text))
        Dim MySource As New AutoCompleteStringCollection()
        MySource.AddRange(suggestions.ToArray)

        With TxtItem
            .AutoCompleteMode = AutoCompleteMode.Suggest
            .AutoCompleteSource = AutoCompleteSource.CustomSource
            .AutoCompleteCustomSource = MySource
        End With
        TxtItem.Select(TxtItem.Text.Length, 0)
        Exit Sub
    Else
        TxtItem.AutoCompleteMode = AutoCompleteMode.None
    End If

End Sub

Note : This issue causes the application exit (sometimes) on Windows XP, but Doesn't affect on Windows 7

Abid Qasem
  • 59
  • 2
  • 6

1 Answers1

0

The answer was found in this post: Dynamically changing Textbox's AutoComplete List causes AccessViolationException, any advice?

So I had to make global list of suggestions and initialize the AutoComplete property in the Form load event and it worked good .

Community
  • 1
  • 1
Abid Qasem
  • 59
  • 2
  • 6