Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
Posted

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;
		}
	}		

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...