Implementar el auto-completar en un ComboBox

2271 vistas

Tenemos que llamar al método FindString en el evento TextChanged del ComboBox:



vbnet
  1. Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
  2.     If Me.ComboBox1.FindString(Me.ComboBox1.Text) > 0 Then
  3.         Dim Pos As Int32 = Me.ComboBox1.Text.Length
  4.         Me.ComboBox1.SelectedIndex = Me.ComboBox1.FindString(Me.ComboBox1.Text)
  5.         Me.ComboBox1.SelectionStart = Pos
  6.         Me.ComboBox1.SelectionLength = Me.ComboBox1.Text.Length - Pos
  7.     End If
  8. End Sub