C# 文本框字符串匹配
我试图根据输入在文本框中提出建议。我正在尝试输入一个数字(例如50),并让文本框显示我要输入的内容。我在vars.str变量中包含以下数据:C# 文本框字符串匹配,c#,C#,我试图根据输入在文本框中提出建议。我正在尝试输入一个数字(例如50),并让文本框显示我要输入的内容。我在vars.str变量中包含以下数据: AU-60-ST-F AU-60-CA-F AU-61-ST-F 这是我正在使用的代码 private void textBox2_TextChanged(object sender, EventArgs e) { AutoCompleteStringCollection col2 = new AutoCompleteStringCollecti
AU-60-ST-F
AU-60-CA-F
AU-61-ST-F
这是我正在使用的代码
private void textBox2_TextChanged(object sender, EventArgs e)
{
AutoCompleteStringCollection col2 = new AutoCompleteStringCollection();
//
for (int i = 0; i < vars.str.Count; i++)
{
if(vars.str[i].IndexOf(textBox2.Text) != -1)
{
label1.Text = "TRUE";
string match = Regex.Replace(vars.str[i], @"-[a-zA-Z][a-zA-Z]-[MF]", "");
col2.Add(match);
}
}
textBox2.AutoCompleteCustomSource = col2;
}
private void textBox2\u TextChanged(对象发送方,事件参数e)
{
AutoCompleteTestringCollection col2=新的AutoCompleteTestringCollection();
//
对于(int i=0;i
如果我在文本框中输入60,建议应该是AU-60,如果我在文本框中输入61,建议应该是AU-61
代码似乎有效-我的测试标签更改为TRUE,但在文本框下面我没有得到任何建议。有什么想法吗?可能重复吗?您是否设置了
textBox2.AutoCompleteMode
?可能重复@zdimension,是的,它设置为textBox2.AutoCompleteMode=AutoCompleteMode.Suggest;您必须将其设置为suggestAppend@J Doe,并且源代码为CustomSource