TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Behrouz Hosseini
NA
72
0
How to Check if an item Exist in a ListBox
May 3 2011 3:04 PM
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";}
}
void Button2Click(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
Reply
Answers (
3
)
Opening and working with excel files using C#
how to sort the values of listbox