簡體   English   中英

我如何才能自動完成組合框匹配字符串的任何部分,而不僅是字符串的開始?

[英]how do I to the auto-completion of combobox match any part of string not only start of string?

假設我有一些物品:

PHP Hypertext Processor
PHP_FOO PHP framework
C#  .NET framework 
Obama american
Bill gates american

我正在尋找一種方法,以確保在組合框項目的任何部分中在comobobox搜索中輸入的所有文本,不僅是在字符串的開頭,還可以將其設置為自動完成建議。

例如:

輸入的文本: ProcessorPHPHypertext匹配: PHP Hypertext Processor文本輸入的PHP Hypertext Processor文本: american匹配: ObamaBill gates等。

匹配項應在組合框中定義為建議。

更新我當前的代碼:

 private void comboBox1_TextChanged(object sender, EventArgs e)
    {
        int i = 0;
        foreach(object item in comboBox1.Items)
        {
            string val = (string)item;
            string[] words = val.Split(' ');

            foreach (string word in words)
            {
                if (word == comboBox1.Text)
                {
                    ////the difficult now it is as set the val variable value in combobox suggestions box?
                }
            }

            i++;
        }

    }

我該怎么做? 我希望這很清楚。 提前致謝。

您的循環也應該更改..如果您知道它將包含文本,請對初學者使用類似這樣的內容。

foreach (string text in combobox1.Items.Cast<string>())
{
     //do stuff with the text
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM