lothos12345 Posted January 24, 2006 Posted January 24, 2006 In a visual basic.net how do I program a combobox to autocomplete from listeditems in a collection that are filled during the run of the application? Any help offered is greatly appreciated. Quote
barski Posted January 24, 2006 Posted January 24, 2006 I got this from msdn some time ago. it's not perfect but it has worked great in windows forms for me. public class DropDownBase : System.Windows.Forms.ComboBox { public DropDownBase() { this.KeyUp+=new KeyEventHandler(ListKeyUp); this.SelectedValueChanged+=new EventHandler(PhysicianChanged); } public void ListKeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { int index; string actual; string found; if ((e.KeyCode == Keys.Back) || (e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right) || (e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Delete) || (e.KeyCode == Keys.PageUp) || (e.KeyCode == Keys.PageDown) || (e.KeyCode == Keys.Home) || (e.KeyCode == Keys.End)) { return; } actual = this.Text; index = this.FindString(actual); if (index > -1) { found = this.Items[index].ToString(); this.SelectedIndex = index; this.SelectionStart = actual.Length; this.SelectionLength = found.Length; } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.