Hi
How to compare the data with listbox and textbox?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted Jan 25, 2009, 7:00 AM EST
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;
}
}