如何比较文本框数据和列表框项目? [英] how to compare the textbox data with listbox items ?

查看:137
本文介绍了如何比较文本框数据和列表框项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较文本框中输入的数据和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


这篇关于如何比较文本框数据和列表框项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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