包含自动完成匹配,而不是StartsWith [英] Autocomplete Match on Contains, not StartsWith

查看:84
本文介绍了包含自动完成匹配,而不是StartsWith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ToolStripTextBox,用它来作为SQL查询的过滤器。

I have a ToolStripTextBox, using it for a filter for a SQL Query.

如果我有列表:

Apple ,橙色,菠萝

Apple, Orange, Pineapple

建议和追加功能将挑选出"Apple"当我过滤"App"时。

The suggest and append features will pick out "Apple" when I filter for "App".

我想改变Suggest部分以包含"Pineapple"。另外(在string.Contains上匹配,而不仅仅是string.Startswith)

I want to alter the Suggest part to include "Pineapple" also (match on string.Contains, not just string.Startswith)

有没有办法拦截像OnSuggestFiltering()这样的东西,或者任何例程处理过滤器?

Is there a way to intercept something like OnSuggestFiltering(), or whatever routine handles the filter?

我宁愿生活在虚假的希望而不是虚伪的绝望中。

I'd rather live with false hope than with false despair.

推荐答案

你好Bryan Valencia,

Hi Bryan Valencia,

感谢您发布此处。

对于您的问题,如果您想使用ToolStripTextBox进行过滤,您想如何显示结果? 

For your question, if you want to filter using ToolStripTextBox, how do you want to show the results? 

自动完成匹配用于StartsWith not Contains。它从左到右过滤。

Autocomplete Match is used for StartsWith not Contains. It filters from left to right.

我建议你使用ToolStripComboBox。这是一个供您参考的简单示例。该示例对案例很敏感。 

I suggest you to use ToolStripComboBox. Here is a simple example for your reference. The example is sensitive of case. 

        List<string> listOnit = new List<string>();
        
        List<string> listNew = new List<string>();


        public Form1()
        {
            InitializeComponent();
        }

        private void BindComboBox()
        {
            listOnit.Add("apple");
            listOnit.Add("Orange");
            listOnit.Add("Pineapple");
this.toolStripComboBox1.Items.AddRange(listOnit.ToArray());
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            BindComboBox();
        }

        private void toolStripComboBox1_TextUpdate(object sender, EventArgs e)
        {          
           this.toolStripComboBox1.Items.Clear();            
            listNew.Clear();         
            foreach (var item in listOnit)
            {
                if (item.Contains(this.toolStripComboBox1.Text))
                {                  
                    listNew.Add(item);
                }
            }        
            this.toolStripComboBox1.Items.AddRange(listNew.ToArray());          
            this.toolStripComboBox1.SelectionStart = this.toolStripComboBox1.Text.Length;           
            Cursor = Cursors.Default;        
            this.toolStripComboBox1.DroppedDown = true;
        }

最好的问候,

Wendy


这篇关于包含自动完成匹配,而不是StartsWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆