Hi
Can you please let me know how I can check if there is a user entered value exist in a listbox? For example if I have a textbox for user to enter a city name and a list of cities how I can check the city name entered in the list box exist in the listbox.I used to methods Contains() and Equals but they didn't work

void Button1Click(object sender, EventArgs e)
		{
			string val = textBox1.Text;
			listBox1.Items.ToString().Contains(label1.Text){
			 label1.Text = listBox1.Items.ToString();
			}
			else{label1.Text = "No such a Item";}
		}

and

void Button1Click(object sender, EventArgs e)
		{
			string val = textBox1.Text;
			listBox1.Items.ToString().Equals(label1.Text){
			 label1.Text = listBox1.Items.ToString();
			}
			else{label1.Text = "No such a Item";}
		}

Thanks for you time

for(int i = 0; i< listBox1.Items.Count; i++)
{
     if(listBox1.Items[i] == textBox1.Text)
     {
         //item found
         break;
     }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.