DataSource in Windows Forms AutoComplete

8 Jul 20263 minutes to read

The AutoComplete component supports a variety of data sources such as DataTables, DataSets, or any component that implements interfaces such as IList, IBindingList, ITypedList, and IListSource. For assigning a data source to AutoComplete, use the DataSource property. This section explains the different types of data binding mechanisms and data settings supported by the AutoComplete component.

Data settings

The data for the autocompletion is maintained by the AutoComplete component itself. This is referred to as History Data List mode. The following properties deal with data settings.

AutoComplete properties Description
CategoryName Specifies a unique or shared name that can be given to an AutoComplete component, so that it can persist the values under that name. For example, when the CategoryName "URL" is provided for an AutoComplete component on a particular form, all the values persisted by that AutoComplete component are also accessible to other AutoComplete component on others forms or on the same form with the CategoryName "URL".
DataSource Sets the Datasource to the AutoComplete component. The AutoComplete component automatically picks the "History Data List" mode or "Data source" mode based on the values set for the DataSource property. When the DataSource property is set to NULL (default value is NULL), the component defaults to History Data List mode. The properties `CategoryName`, `AutoAddItem`, and `AutoSerialize` have to be set appropriately for the History Data List mode to work properly.
this.autoComplete1.CategoryName = "FTP";

this.autoComplete1.DataSource = DataTable1;
Me.autoComplete1.CategoryName = "FTP"

Me.autoComplete1.DataSource = DataTable1

Dynamic source at run time

Enabling the AutoAddItem property allows you to save your entries at runtime. Pressing the Enter key adds the current entry to the history list.

Built-in source

The different built-in sources (FileSystem, HistoryList, AllUrl, etc.) can be set on the editor control using the standard System.Windows.Forms.AutoCompleteSource property, which is then used by the Syncfusion AutoComplete component when bound to that editor.

Built-in DataSource Support. Description
FileSystem It specifies file system as source.
HistoryList Includes all the URLs in the history list.
RecentlyUsedList Includes a list of most recently used URLs.
AllUrl Equivalent source of HistoryList and RecentlyUsedList as the source.
AllSystemSources Equivalent source of AllUrls and FileSystem as the source (default value of AutoCompleteSource when AutoCompleteMode is set to some values other than default value).
ListItems Specifies the items in the control.
FileSystemDirectories Specifies directory names alone without file names.
CustomSource Uses the string values entered in AutoCompleteCustomSource property.
None There is no source for the auto completion.
this.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.HistoryList;
Me.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.HistoryList

Windows Forms AutoComplete History List in datasource

Custom source

The AutoComplete component allows you to add a set of text using the String Collection Editor, which is shown by clicking the AutoCompleteCustomSource property in the property window of the editor control. The AutoCompleteSource property should be set to CustomSource to use the custom items added through the String Collection Editor.

Windows Forms AutoComplete Customsource datasource

this.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;

    this.textBox1.AutoCompleteCustomSource.AddRange(new string[] {"Syncfusion", "AutoComplete",
    "Item Customization", "Popup Customization", "DataBinding"});
Me.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource


    Me.textBox1.AutoCompleteCustomSource.AddRange(New String[] {"Syncfusion", "AutoComplete",
    "Item Customization", "Popup Customization", "DataBinding"})

Windows Forms AutoComplete Customsource datasource

Binding custom collections

The different custom collections that can be bound to the DataSource property of the AutoComplete component are listed as follows.

  • BindingList Collection
  • ArrayList Collection
  • Observable Collection
  • Collection Base
  • Generic Collections
  • DataTable

A sample that demonstrates binding various data sources is available here.