C-Sharp: AutoComplete Text Box and Combo Box

I can remember in VB 6 for auto complete text in ComboBox and TextBox, we are writing codes for doing that. This auto complete features are also available with several web browsers.

For doing this in dotnet windows application dotnet TextBox and ComboBox classes are providing  properties and methods to do this functionality very efficiently.

For this TextBox and ComboBox classes exposed three properties, by using them we can achieve this auto complete feature.

  1. AutoCompleteMode
  2. AutoCompleteSource
  3. AutoCompleteCustomSource

For example i want to get auto complete suggestion for recent file, web urls. To do this i have written just code given below and you will get result.

            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.AllUrl;

When you will run application and type any thing in textBox1 then you will get auto complete suggestion as given below.

Autocomplete snap

AutoCompleteMode and AutoCompleteSource properties of TextBox / ComboBox are used to do this.


Specifies the mode for the automatic completion feature used in the ComboBox and TextBox controls.

  1. None: Disables the automatic completion feature for the ComboBox and TextBox controls.
  2. Suggest: Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.
  3. Append: Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.
  4. SuggestAppend: Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.


Specifies the source for ComboBox and TextBox automatic completion functionality. This has following enumerations.

  1. FileSystem: Specifies the file system as the source.
  2. HistoryList: Includes the Uniform Resource Locators (URLs) in the history list.
  3. RecentlyUsedList: Includes the Uniform Resource Locators (URLs) in the list of those URLs most recently used.
  4. AllUrl: Specifies the equivalent of System.Windows.Forms.AutoCompleteSource.HistoryList and System.Windows.Forms.AutoCompleteSource.RecentlyUsedList as the source.
  5. AllSystemSources: Specifies the equivalent of AutoCompleteSource.FileSystem and AutoCompleteSource.AllUrl as the source. This is the default value when AutoCompleteMode has been set to a value other than the default.
  6. FileSystemDirectories: Specifies that only directory names and not file names will be automatically completed.
  7. CustomSource: Specifies strings from a built-in AutoCompleteStringCollection as the source.
  8. None: Specifies that no System.Windows.Forms.AutoCompleteSource is currently in use. This is the default value of System.Windows.Forms.AutoCompleteSource.
  9. ListItems: Specifies that the items of the System.Windows.Forms.ComboBox represent the source.

When autocomplete source is CustomSource then we have to use AutoCompleteCustomSource property of TextBox/ ComboBox class property to use custom string in suggestion list.

            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            AutoCompleteStringCollection list = new
            list.AddRange(new string[]{"one","two","three"});
            textBox1.AutoCompleteCustomSource = list;

Tips: You can use string fro data sources like Database, Webservices to get string list and add them to a AutoCompleteStringCollection object and assign this object to TextBox / ComboBox AutoCompleteCustomSource  property to get live suggestion.

Leave a Reply

Your email address will not be published. Required fields are marked *