The previous article is to use a ComboBox inside the original event to achieve fuzzy query, the operation is more flexible, but received comments that the use of AutoComplete attributes can be used to achieve fuzzy query, but according to my understanding, autocomplete although can easily realize fuzzy query, However, there is a certain flaw, that is, fuzzy query can only go from left to right.
Previous link Address: http://www.cnblogs.com/xilipu31/p/3993049.html
Here's a simple way to implement it:
Front Desk: A simple form +combobox control
Backstage: assert that list<string> listonit is used to initialize the alternate data for the ComboBox and then set the ComboBox property: AutoCompleteSource (auto-complete data source), AutoCompleteMode ( Prompt type) and AutoCompleteCustomSource (bound data source).
The specific code is as follows:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace timerdemo{public partial class Form3:form {//Initialize binding default keywords (this data source can be taken from the database) list<string> listonit = new list<string> (); Public Form3 () {InitializeComponent (); } private void Form3_load (object sender, EventArgs e) {bindcombobox (); }///<summary>//Binding ComboBox///</summary> private void Bindcombobox () { Listonit.add ("Zhang San"); Listonit.add ("Zhang Sizhong's"); Listonit.add ("Zhang Five"); Listonit.add ("Harry"); Listonit.add ("Yulaw"); Listonit.add ("Caifan"); Listonit.add ("Sun Nan"); Listonit.add ("that English"); Listonit.add ("Liu Huan"); Auto-complete data source This.comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; Hint type suggestion list + auto complement This.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; Bind data Source This.comboBox1.AutoCompleteCustomSource.AddRange (Listonit.toarray ()); } }}
The following are the implementation effects:
Input keyword fuzzy query from left to right (for example, input: Zhang)
The correct hints and results can be drawn.
What if it's not a fuzzy query from left to right? (e.g. input: three)
It can be seen that fuzzy data cannot be queried.
Summarize:
ComboBox Control AutoComplete event can be used in the Fuzzy query degree is not high, left-to-right keyword search, if you want to implement advanced fuzzy query, or their own definition of the way more flexible.
WinForm in a ComboBox using AutoComplete property to implement Fuzzy query (defective)