WinForm in a ComboBox using AutoComplete property to implement Fuzzy query (defective)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.