如何比较文本框数据和列表框项目?
问题描述:
如何比较文本框中输入的数据和lisbox中插入的项目?如果数据匹配,则从
How the compare the the data entered in textbox with the items inserted in lisbox ? if data matches proceed to next from
答
尝试:
if (myListBox.Items.Contains(myTextBox.Text))
{
Console.WriteLine("YES");
}
尝试
foreach(ListItem item in yourlstbox.Items)
{
if(item.Text == yourtxtName.Text)
{
// isExists = true; your condition
break;
}
}
或更好地在TextBox的TextChangedEvent代码上编写代码,例如:-
or better to write code on TextBox''s TextChangedEvent code like :-
private void textBox1_TextChanged(object sender, EventArgs e)
{
int index = listBox1.FindString(this.textBox1.Text);
if (0 <= index)
{
listBox1.SelectedIndex = index;
}
}
参考链接:-在ListBox中搜索与TextBox文本进行比较的值(增量搜索)在C#中 [
Reference Link :- Search an Value in ListBox with compare to TextBox Text(Incremental Search) in C#[^]
kmfvvvvvvvvvvvvvvv dccccccccccccccccccccccccc
kmfvvvvvvvvvvvvvvv dccccccccccccccccccccccc