Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
How the compare the the data entered in textbox with the items inserted in lisbox ? if data matches proceed to next from
Posted

Try:
C#
if (myListBox.Items.Contains(myTextBox.Text))
    {
    Console.WriteLine("YES");
    }
 
Share this answer
 
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
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 :-

C#
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#[^]
 
Share this answer
 
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
kmfvvvvvvvvvvvvvvv dccccccccccccccccccccccc
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900