Implementar el auto-completar en un ComboBox

1905 vistas

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



csharp
  1. private void ComboBox1_TextChanged(object sender, EventArgs e)
  2. {
  3.     if (this.ComboBox1.FindString(this.ComboBox1.Text) > 0)
  4.     {
  5.         int pos = this.ComboBox1.Text.Length;
  6.         this.ComboBox1.SelectedIndex = this.ComboBox1.FindString(this.ComboBox1.Text);
  7.         this.ComboBox1.SelectionStart = pos;
  8.         this.ComboBox1.SelectionLength = this.ComboBox1.Text.Length - pos;
  9.     }
  10. }