Example of the C # ComboBox AutoComplete feature
DataTable dt = new DataTable ();
Dt. Columns.Add ("Name");
Dt. Columns.Add ("VV");
Dt. Rows.Add (new string[] {"Wang Yi", "x"});
Dt. Rows.Add (new string[] {"Zhao Yi", "Z"});
Dt. Rows.Add (new string[] {"King II", "Y"});
Dt. Rows.Add (new string[] {"Zhao II", "w"});
This.comboBox1.DataSource = DT;
This.comboBox1.DisplayMember = "Name";
This.comboBox1.ValueMember = "VV";
This.comboBox1.AutoCompleteSource = Autocompletesource.listitems; Set the source for AutoComplete
This.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; Set the form of automatic completion
The above AutoCompleteSource is everybody should pay attention to, the concrete value has 9 kinds of choice, among them 8 kinds can study the
————————————————————————————————
The difference between DisplayMember and ValueMember properties:
DisplayMember bound is the field you want to display
ValueMember is bound by the corresponding value
//*
The corresponding value is a record with the identity column ID (unique) There are displayed columns (such as name, repeatable)
ValueMember can be a name or an ID
But generally it is only binding ID so good processing, but also easy to identify,
DisplayMember is the data that is bound to display such as: Beijing
The general DisplayMember is displayed to the customer to see
And ValueMember is what the binding handler identifies to the programmer.
Of course it depends on the specific needs.
*//
The ComboBox control displays the DisplayMember bound field, meaning that the value taken with the control's Text property is a displaymember bound field.
And with combo. SelectedValue can obtain the ValueMember value of the selected item (not confirmed).
SelectedValue property: Gets or sets the value of the member property specified by the ValueMember property.
————————————————————————————————————
You can also use Combox. Items.Add ("Contents of items"); method to insert a field.
————————————————————————————————————
AutoCompleteMode Properties:
Gets or sets the option to control how AutoComplete acts on ComboBox. That is, the form of automatic completion.
Its value range:
None disables the AutoComplete feature of the ComboBox and TextBox controls.
Suggest displays the secondary Drop-down list associated with the edit control. This drop-down list populates one or more of the recommended completion strings.
Append appends the remainder of the most likely candidate string to an existing character and highlights the appended characters.
SuggestAppend applies both suggest and Append options. Displays both the Drop-down list and the text automatically appended.
————————————————————————————————————
AutoCompleteSource Properties:
Gets or sets a value that specifies the source of the completion string that is used for AutoComplete. Specifies the source of the auto completion.
Its value range:
FileSystem Specifies the file system as the source.
Historylist includes a Uniform Resource Locator (URL) in the History list.
Recentlyusedlist includes the Uniform Resource Locator (URL) in the list of recently used URLs.
ALLURL specifies the equivalent of historylist and recentlyusedlist as the source.
ALLSYSTEMSOURCES Specifies the equivalent of filesystem and Allurl as the source. This is the default value when AutoCompleteMode is set to a value instead of the default value.
Filesystemdirectories specifies that only the directory name is automatically completed without the file name being automatically completed.
CUSTOMSOURCE specifies the string in the built-in autocompletestringcollection as the source.
None specifies that no autocompletesource is currently being used. This is the default value for AutoCompleteSource.
LISTITEMS Specifies the item representation source for the ComboBox.
————————————————————————————————————
Although the above automatic completion function can basically meet the daily use, but I want to automatically complete the fuzzy automatically match the input text before the part, such as "Peking University", as long as the input "Beijing" can be found. However, the above method can only be implemented after the input "China", automatically fill the back section, or show all the "China" as the beginning of items.