Introduction
Most of the developers are familiar with the auto-completion text feature available in browsers, search controls, and other controls. The auto-completion feature is when you start typing some characters in a control, the matching data is loaded automatically for you.
In Visual Studio 2005, some of the controls support this feature including the ComboBox and the TextBox controls. By using these features, we can build Internet Explorer-like auto-completion functionality in our Windows Forms applications.
In Visual Studio 2005, some of the controls support this feature including the ComboBox and the TextBox controls. By using these features, we can build Internet Explorer-like auto-completion functionality in our Windows Forms applications.
Now, we can have a combo box that completes URLs as soon as you type any character. For example, in Figure 1, I typed "c-s" and I see all the URLs starting with "c-s".

Figure 1. Auto-Completion in a ComboBox
The AutoCompleteSource and AutoCompleteMode properties of the TextBox and ComboBox controls allow developers to provide automatic completion text features. You can set both of these properties at design-time as well as at run-time. If you click on AutoCompleteSource drop down, you will see all the options in the drop-down list. See Figure 2.
Figure 2. AutoCompleteSource options
Figure 3 shows AutoCompleteMode options.
Figure 3. AutoCompleteMode options
You can also set these properties at run-time using the following code:
- comboBox1.AutoCompleteSource = AutoCompleteSource.AllSystemSources;
- comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
-
AllSystemResources - Specifies the equivalent of FileSystem and AllUrl as the source. This is the default value when AutoCompleteMode has been set to a value other than the default.
-
AllUrl - Specifies the equivalent of HistoryList and RecentlyUsedList as the source.
-
CustomSource - Specifies strings from a built-in AutoCompleteStringCollection as the source.
-
FileSystem - Specifies the file system as the source.
-
FileSystemDirectories - Specifies that only directory names and not file names will be automatically completed.
-
HistoryList - Includes the Uniform Resource Locators (URLs) in the history list.
-
ListItems - Specifies that the items of the ComboBox represent the source.
-
None - Specifies that no AutoCompleteSource is currently in use. This is the default value of AutoCompleteSource.
-
RecentlyUsedList - Includes the Uniform Resource Locators (URLs) in the list of those URLs most recently used.
The AutoCompleteMode enumeration has the following members:
-
Append - Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.
-
None - Disables the automatic completion feature for the ComboBox and TextBox controls.
-
Suggest - Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.
-
SuggestAppend - Applies both Suggest and Append options.
Loading Custom Source
We can also specify a custom source from where the listing will be loaded. If you click on the AutoCompleteCustomSource property, it will open the String Collection Editor, where we can add our strings. For example, I add the following strings to the strings list. See Figure 4.
Figure 4. Custom Source strings
Now we need to set AutoCompleteSource to CustomSource:
- comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
Figure 5. Custom Source listing
We can also create AutoCompleteStringCollection programmatically. The following code creates an AutoCompleteStringCollection, adds strings to the collection, and sets it to the AutoCompleteCustomSource of the ComboBox.
- // AutoCompleteStringCollection
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- data.Add("Mahesh Chand");
- data.Add("Mac Jocky");
- data.Add("Millan Peter");
- comboBox1.AutoCompleteCustomSource = data;
Figure 6. Loading custom data
Summary
The AutoComplete feature of ComboBox and TextBox controls allow us to set the autocomplete text feature. In this article, we saw how to use this feature in our application at design-time as well as at run-time.

Former memberPosted Aug 13, 2020, 2:20 PM
Where is the Explanation and code for the following Now, we can have a combo box that completes URLs as soon as you type any character. For example, in Figure 1, I typed "c-s" and I see all the URLs starting with "c-s".
kalu singh raoPosted Jul 7, 2016, 1:46 AM
Nice...
vinayPosted Apr 29, 2016, 3:16 AM
Hello Mahesh, could you please guide what could I do to make auto suggest work matching any word in the source phrase and not just the starting characters.
BalaMurali KrushnaPosted Jan 23, 2015, 9:01 AM
Mahesh, try to answer the question posted in the below link: ---https://social.msdn.microsoft.com/Forums/vstudio/en-US/7c08a688-8671-4d94-b465-4ae8ba3cdf7b/combobox-autocompletemode-autocompletemodesuggestappend-how-to-prevent-the-user-typing-invalid?forum=vbgeneral
BalaMurali KrushnaPosted Jan 23, 2015, 9:00 AM
https://social.msdn.microsoft.com/Forums/vstudio/en-US/7c08a688-8671-4d94-b465-4ae8ba3cdf7b/combobox-autocompletemode-autocompletemodesuggestappend-how-to-prevent-the-user-typing-invalid?forum=vbgeneral
sat chPosted Mar 25, 2014, 4:13 AM
Very helpful Thank you...........
mahesh kumar B MPosted Dec 25, 2013, 4:31 AM
hey mahesh this works only for th every first value that u populate in case if u r populating in the text box. IF I want to populate the multiple values in text box using this feature,how to do this like the one we seee in the to address fileds of outlook.Here after entering semicolon then tyr to enter next value,again it suggests and appends.I want to include that feature...
Mo BoPosted May 15, 2013, 4:30 AM
How do you control the size of dropdown? I am doing application for touch screen and all my searching turns that I have to create a custom control. However, it's not as smooth as the suggestion box.
manoj jaiswalPosted Jan 2, 2013, 7:51 AM
its ok .... but i want to search condition on string any where in the string. i have used combobox text changed event.... here is my code private void cmbTest_TextChanged(object sender, EventArgs e) { string item = cmbTest.Text; item = item.ToLower(); cmbTest.Items.Clear(); List<string> list = new List<string>(); List<string> listComp = new List<string>(); for (int i = 0; i < dtvender.Rows.Count; i++) { listComp.Add(dtvender.Rows[i]["FullName"].ToString()); if (dtvender.Rows[i]["FullName"].ToString().ToLower().Contains(item))// arrayOld[i].ToLower().Contains(item)) list.Add(dtvender.Rows[i]["FullName"].ToString()); } if (item != String.Empty) foreach (string str in list) cmbTest.Items.Add(str); else foreach (string str in listComp) cmbTest.Items.Add(str); cmbTest.SelectionStart = item.Length; cmbTest.DroppedDown = true; } its work fine but when we use up down arrow key then after selecting first item list goes away.... In your code if i press m then Mac Jocky,Mahesh Chand,Millan Peter comes in the list and on pressing up down key we can select any one of the three .I want to implement same process with string any where in the Combobox..... Please give me the solution...........
AmolPosted Sep 8, 2011, 8:25 AM
nice to see such a amazing article...
Waqas MehmoodPosted Aug 25, 2011, 2:52 AM
can u give the same functionality textbox in WPF ?????
rajesh narayasamiPosted Sep 15, 2010, 5:19 AM
[WebMethod] public string[] getClients(string prefixText, int count) { if (count == 0) { count = 10; } string key = prefixText + "%"; string qry = "SELECT COUNT(id) FROM tb_123_clients WHERE client LIKE '" + key + "'"; dr = dbu.executeReader(qry); if (dr.Read()) { count = dr.GetInt32(0); } dr.Close(); string[] items = new string[count]; qry = "SELECT client FROM tb_123_clients WHERE client LIKE '" + key + "'"; dr = dbu.executeReader(qry); int i = 0; while (dr.Read()) { items.SetValue(dr["client"].ToString(), i); i++; } dr.Close(); return items; }
CheeyamPosted Aug 20, 2010, 6:29 AM
Hi, I have two textboxes. As I type in one of them, there should be autosuggestion in the other one. Is this possible? Thx
megha guptaPosted Jul 26, 2010, 4:01 AM
Hi!!! This is Megha, well i want to know is there any method via which we could change the font size of the autocomplete list. I had tried changing the font size of the textbox this changes the font size of the text box but the list beneath it that matches the Autocomplete feature is of the smaller font only.
SirousPosted Jun 25, 2010, 4:04 AM
sir, Is there a way to have the autocomplete feature in the middle of a sentence? It works for the first word, but not after that.
arthurPosted Jun 20, 2010, 4:30 PM
Tnx :)
dinesh kPosted Mar 21, 2010, 3:33 PM
super super super coding sir thanks lot sir
PrzemekPosted Jul 18, 2009, 3:17 PM
As MVP you didn't make much effort to write this article. Did you?
Allan FournierPosted Apr 10, 2009, 5:33 PM
I can get autocomplete to work with a standalone TextBox. But with the following C# code, I never see the auto complete drop down. Also, is it possible to see the auto complete dropdown on activation of the control, rather than after User hits first key? private void loopsDataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { string[] paramStrings = { "OUT1", "OUT2" }; AutoCompleteStringCollection autoStrings = new AutoCompleteStringCollection(); autoStrings.AddRange(paramStrings); TextBox textbox = loopsDataGridView.EditingControl as TextBox; textbox.AutoCompleteCustomSource = autoStrings; textbox.AutoCompleteMode = AutoCompleteMode.SuggestAppend; textbox.AutoCompleteSource = AutoCompleteSource.CustomSource; }
daniel sovinoPosted Jan 16, 2008, 12:54 AM
I would like to know if there's any way I can display the auto-complete list as soon as the control gets focused? (onclick should work also)
nagamanieditedPosted Nov 15, 2007, 2:00 AMEdited Nov 15, 2007, 2:11 AM
very urgent hello sir i want to select Mac Jocky (combobox item) by pressing Return key
Michael DyeeditedPosted Jun 13, 2006, 8:42 AMEdited Oct 3, 2006, 11:59 AM
Thanks for the article. We've now used autocomplete in our application and, quite simply, the users don't reckon it's working! This is because the "restart" delay is too quick - they type a few characters, pause for thought, and type the rest - only for the autocomplete to have restarted (we use the append type). Is there any control over this delay? In our comboboxes the "key" they are trying to find (from a list of thousands) is up to 15 characters long (letters and numbers) - so they need to be able to type this in slowly! Thanks, Dr. Michael Dye.
shitesh shuklaPosted Mar 13, 2006, 1:50 AM
hi! this is shitesh shukla(new to c#.net). i tried yours autocopmlete feature in combo box but there is no such attribute in the framework which i am using.i am using version1.1(2001-2002). is autocomplete feature of combo box is newly added in advance version? thanks and regards Shitesh shukla