我如何自动完成组合框匹配字符串的任何部分,而不仅仅是字符串的开始
本文关键字:字符串 任何部 开始 不仅仅是 何自动 组合 | 更新日期: 2023-09-27 18:18:43
假设我有条目作为它:
PHP Hypertext Processor
PHP_FOO PHP framework
C# .NET framework
Obama american
Bill gates american
我正在寻找一种方法,任何文本输入在组合框搜索的任何部分的组合框项目,不仅在字符串的开始,并将其设置为自动补全建议。
例如:文本输入:Processor
或PHP
或Hypertext
match: PHP Hypertext Processor
文本输入:american
匹配:Obama
和Bill 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
}