Click here to Skip to main content
15,792,397 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to check new item adding to the combox is in the same combobox items.

can u plz help me..
i tried following code...

for (int i = 0; i <= cmbdep.Items.Count; i++)
                      if (cmbdep.Text == cmbdep.Items.ToString())
                          c = 1;
                          c = 0;

but not working...

I am not sure why you think this will work. Why not use foreach to iterate over the items ? Items.ToString() is obviously not using your index. Try Items[i].Text, that would mean you were not checking the same thing over and over, but instead checking each individual item.

Also, why use 'c' instead of a bool ?
Share this answer
Ragi Gopi 2-Jul-11 4:03am    
It all makes no sense, plus a couple of bugs:

You make one iteration more that the number of items; use < instead of <= in the loop ending condition.

Also, cmbdep.Items.ToString() will not return what you expect. You probably wanted an item by index, so use cmbdep.Items[i].ToString().

The calculation if c makes no sense. Do you simply want check up if the text is one of the items? (You don't have to answer. :-))

Share this answer
Ragi Gopi 2-Jul-11 4:03am    
Sergey Alexandrovich Kryukov 3-Jul-11 2:12am    
You're welcome.
Good luck, call again.

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