Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VS 2005 improvement question
Message
From
27/12/2006 12:53:59
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
00973790
Message ID:
01180534
Views:
25
Yeah, Kirk ... thanks. I subsequently discovered that as well, but the implementation that MS has for this leaves much to be desired, IMHO. I've done my own, which I borrowed and tweaked from some code somewhere (forgot where, it may have been CodeProject, but don't quote me on that). This class was subclassed from MyComboBox subclass, but it should probably work fine sub-classed from the System.Windows.Forms.ComboBox base class.
	public class MyComboBoxAutoComplete : MyComboBox
	{
		#region Declarations

		private bool InEditMode = true;

		#endregion

		#region Constructor

		public MyComboBoxAutoComplete()
		{
			this.DropDownStyle = ComboBoxStyle.DropDown;
			this.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
			this.AutoCompleteSource = AutoCompleteSource.ListItems;
		}
		#endregion

		#region Events

		protected override void OnBindingContextChanged(EventArgs e)
		{
			this.DropDownStyle = ComboBoxStyle.DropDown;
			base.OnBindingContextChanged(e);
		}
		protected override void OnValidating(CancelEventArgs e)
		{
			int index = this.FindStringExact(this.Text);
			if (index >= 0 || this.Text.Trim() == "")
				base.OnValidating(e);
			else
				e.Cancel = true;
		}
		protected override void OnKeyDown(KeyEventArgs e)
		{
			this.InEditMode = (e.KeyCode != Keys.Back && e.KeyCode != Keys.Delete);
			base.OnKeyDown(e);
		}
		protected override void OnTextChanged(EventArgs e)
		{
			if (this.InEditMode)
			{
				int index = this.FindString(this.Text);
				if (index < 0 && this.Text.Trim() != "")
				{
					this.InEditMode = false;
					this.Text = this.Text.Substring(0, this.Text.Length - 1);
					this.InEditMode = true;
					this.Select(this.Text.Length, this.Text.Length);
				}
			}

			base.OnTextChanged(e);
		}

		#endregion
	}
~~Bonnie


>Bonnie
>
>You may have this already figured out, but I just learned it.
>
>In winforms on the combobox, you set the Autocomplete source to listitems.
>
>Kirk
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform