title: .NET fulltext autocomplete in a combobox. Any performance-positive way of overriding listitems?
body: <p>I'm struggling to meet a demand from my supervisors. I really hope that someone could give some advice.
  Basically there are places in our project where there is a big selection of options. The most concrete example is choosing a city in the world. The items are hundreds of thousands. 
  Using standard winforms controls and properties, one can search through a list fast.
  The problem is that we're using a concatenation of city&amp;district name for all the items. Essentially PREFIX autotomplete works but does not work as needed. The task is to filter and show items by any given string in any part of the item. Essentially a FULL TEXT search in the combobox.
  Does anyone have an idea about switching autocomplete sources in runtime relatively qiuckly and handling the suggest/suggestappend event? 
  Also the project is in VB.NET, though any form of .NET advice will be extremely helpful.</p>
  
  <p>Thanks!</p>
  
  <p>UPDATE: The latest attempt using <a href="https://stackoverflow.com/users/1002323/competent-tech">competent_tech</a>'s suggestion with some minor modifications.</p>
  
  <pre><code>Imports System.Data
  Public Class Form1
  Private _ErrorText As String
  Private _CommandExecuted As Boolean
  
  Private m_fOkToUpdateAutoComplete As Boolean
  Private m_sLastSearchedFor As String = ""
  
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Call Me.SetStatusText("Loading...")
      Me._ErrorText = ""
      Me.Cities.Clear()
      Me.BackgroundWorker1.RunWorkerAsync()
  End Sub
  
  Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
      Try
          Me._CommandExecuted = True
          Me.Ara_airportsTableAdapter.Fill(Me.Cities.ara_airports)
      Catch ex As Exception
          _ErrorText = ex.Message
      End Try
  End Sub
  
  Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
      If Me._ErrorText = "" Then
          Me.SetStatusText(Me.Cities.ara_airports.Count &amp; " Records loaded")
      Else
          Me.SetStatusText(Me._ErrorText)
      End If
      Me.BindingSource.ResetBindings(False)
  End Sub
  
  Private Sub SetStatusText(ByVal sText As String)
      Me.Text = sText
  End Sub
  
  Private Sub cboPort_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboPort.KeyDown
      Try
          If e.KeyCode = Keys.Up OrElse e.KeyCode = Keys.Down Then
              m_fOkToUpdateAutoComplete = False
          Else
              m_fOkToUpdateAutoComplete = True
          End If
      Catch theException As Exception
          ' ...
      End Try
  End Sub
  
  Private Sub cboPort_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPort.KeyUp
      Try
          If m_fOkToUpdateAutoComplete Then
              With cboPort
                  If .Text.Length &gt;= 2 Then
                      Dim cSuggestions As IList
                      Dim sError As String = ""
  
                      m_sLastSearchedFor = .Text
  
                      cSuggestions = GetSuggestions(m_sLastSearchedFor)
                      .DataSource = Nothing
                      If cSuggestions IsNot Nothing Then
                          .BindingContext = New BindingContext
                          .DisplayMember = "CName"
                          .ValueMember = "id"
                          .DataSource = New BindingSource(cSuggestions, Nothing)
  
                          System.Threading.Thread.Sleep(10)
                          System.Windows.Forms.Application.DoEvents()
                          .DroppedDown = True
                          .Text = m_sLastSearchedFor
                          If .Text.Length &gt; 0 Then .SelectionStart = .Text.Length
                      End If
                  End If
              End With
          End If
      Catch theException As Exception
          ' ...
      End Try
  End Sub
  
  Private Function GetSuggestions(ByVal searchFor As String) As IList
      BindingSource.Filter = "CName LIKE '%" &amp; searchFor &amp; "%'"
      Return BindingSource.List
  End Function
  
  End Class
  </code></pre>