Click here to Skip to main content
12,074,549 members (59,133 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Forms
How the compare the the data entered in textbox with the items inserted in lisbox ? if data matches proceed to next from
Posted 18-Dec-11 3:00am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try:
if (myListBox.Items.Contains(myTextBox.Text))
    {
    Console.WriteLine("YES");
    }
  Permalink  
Comments
zahra1991 18-Dec-11 8:25am
   
private void button1_Click(object sender, EventArgs e)
{
if (listBox1.FindStringExact(this.textBox1.Text,0) == 0)
{MessageBox.Show("Found");
Form2 f = new Form2();
f.Show();
}
else
MessageBox.Show("Not Found");

}
have tried this , but its not working
OriginalGriff 18-Dec-11 8:30am
   
Did I say to use FindStringExact? No, I didn't think I did...
zahra1991 18-Dec-11 8:35am
   
but you wrote console.writeline .. i actually wnt to compare the text what i have entered in the textbox with listbox items.. when i click on button if the data matches it should proceed to next form
OriginalGriff 18-Dec-11 9:39am
   
So replace the Console code with the code to open your form?
Are you a programmer and capable of thinking for yourself or only capable of following instructions? Because if it is the latter, then you need to change courses...
PramodSawant 6-Nov-12 6:17am
   
OriginalGriff is right!!! @zahra1991-are you a programmer? or you dont know how to show next Form
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try
foreach(ListItem item in yourlstbox.Items)
{
if(item.Text == yourtxtName.Text)
{
// isExists = true;  your condition 
break;
}
}

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;
}
}

Reference Link :- Search an Value in ListBox with compare to TextBox Text(Incremental Search) in C#[^]
  Permalink  
v2
Comments
zahra1991 18-Dec-11 8:24am
   
private void button1_Click(object sender, EventArgs e)
{
if (listBox1.FindStringExact(this.textBox1.Text,0) == 0)
{MessageBox.Show("Found");
Form2 f = new Form2();
f.Show();
}
else
MessageBox.Show("Not Found");

}
have tried this but its not working
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

kmfvvvvvvvvvvvvvvv dccccccccccccccccccccccc
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100