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:

  

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms; namespaceTimerDemo{    publicpartialclassForm3 : Form    {        //初始化绑定默认关键词(此数据源可以从数据库取)        List<string> listOnit = newList<string>();        publicForm3()        {            InitializeComponent();        }        privatevoidForm3_Load(objectsender, EventArgs e)        {            BindComboBox();        }        /// <summary>        /// 绑定ComboBox        /// </summary>        privatevoidBindComboBox()        {            listOnit.Add("张三");            listOnit.Add("张思");            listOnit.Add("张五");            listOnit.Add("王五");            listOnit.Add("刘宇");            listOnit.Add("马六");            listOnit.Add("孙楠");            listOnit.Add("那英");            listOnit.Add("刘欢");            //自动完成数据源            this.comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;            //提示类型  建议列表+自动补全            this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;            //绑定数据源            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.