Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
Wonder if someone can help with the following:
I have a string that need to be compared with items in a combobox. this is the code

VB.NET
For i = 0 To ddlReasons.Items.Count - 1
If ddlReasons.Items(i).ToString = strreason Then
              ShowMessageDialog("This reason is already present",MsgBoxStyle.Information)
              Exit Sub
          End If
     Next


please help..
Thanks
Posted
Updated 19-May-11 3:02am
v2
Comments
ZeeroC00l 19-May-11 9:03am    
-- added 'pre' tag
Abhinav S 19-May-11 9:06am    
So where is the problem?
nagendrathecoder 19-May-11 9:36am    
What is problem in that, though you got a better solution.
AnnSJ 20-May-11 1:44am    
the problem is that ddlreasons.item(i) does reflect the value present in the drop down. so the comaprison always fails.

1 solution

I am assuming that your combo box is ddlReasons

dim i as integer = 0
i =  ddlreasons.findString(StringVariable)


Where StringVariable is the string that you want to find.
 
Share this answer
 
Comments
nagendrathecoder 19-May-11 9:35am    
Good answer, my 5.
AnnSJ 20-May-11 1:43am    
Thanks.
I had used the FIndStringExact method in my if condition n it didn work ( still not sure y!!).
Wheni changed it to assign the result to a variable n then compare the value of variable it did.
Thanks :)
Simon_Whale 20-May-11 4:21am    
your Welcome :)

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