Feature Overview
Related properties
Textbox.autocompletecustomsource Property
Gets or sets the custom t:system.collections.specialized.stringcollection to use when the Textbox.autocompletesource property is set to [CustomSource].
Textbox.autocompletemode Property
Gets or sets an option that controls how automatic completion is applied to a TextBox.
Property Value
Type: System.Windows.Forms.AutoCompleteMode
One of the AutoCompleteMode values. These values are the following.
Append
Appends the remainder of the most likely candidate string to an existing character and highlights the appended character.
Suggest
Displays the secondary drop-down list associated with the edit control. This drop-down list fills in one or more suggested completion strings.
SuggestAppend
Append Suggest and Append options.
None
Disable Auto-completion This is the default value.
Textbox.autocompletesource Property
Gets or sets a value that specifies the source of the complete string that is used for auto-completion.
Note
Use the AutoCompleteCustomSource, AutoCompleteMode, and AutoCompleteSource properties to create a TextBox that It automatically completes the input string by comparing the prefix entered with the prefix of all the strings in the maintained source. This is useful for TextBox controls that frequently have URL, address, file name, or command input.
The use of the AutoCompleteCustomSource property is optional, but you must set the AutoCompleteSource property to CustomSource before you can use AutoCompleteCustomSource.
The AutoCompleteMode and AutoCompleteSource properties must be used together.
Sample code
The following code example demonstrates how to use a collection of custom sources that are auto-completed as a TextBox control.
This example performs the following actions:
Use the AutoCompleteSource property to enable a TextBox control to accept a custom source for its AutoComplete behavior.
Use the AutoCompleteCustomSource property to set a custom list of values.
Use the AutoCompleteMode property to set how candidates are displayed automatically.
private void Form1_Load(object sender, EventArgs e)
{
var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
});
textBox1.AutoCompleteCustomSource = source;
textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
}