hi
How to compare the data with listbox and textbox?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott LyslePosted Jan 25, 2009, 12:00 PM
Not sure what you mean; here is a way to search for a match and a way to select (highlight) a match:
// search for a match
private void button1_Click(object sender, EventArgs e)
{
foreach (string s in listBox1.Items)
{
if (s == textBox1.Text)
MessageBox.Show("Found: " + s);
}
}
// select the match
private void button2_Click(object sender, EventArgs e)
{
for(int i=0; i
{
if (listBox1.Items[i].ToString() == textBox1.Text)
listBox1.SelectedIndex = i;
}
}