Click here to Skip to main content
15,943,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

In my application at button click i am clearing my combo box


But when ever the control is going to this line, it's automatically redirecting to it's SelectionChanged event and throwing error.

Please tell me what is the problem.
Thanks7872 26-Sep-13 2:52am    
Its very much clear from the event name itself. Whenever selection changes,it will be called. On button click,you are changing the selection from whatever it is.
[no name] 26-Sep-13 3:23am    
No..u can see the line i wrote above. that's the only thing i am doing in my button click..then how come it is relate to that.
Thanks7872 26-Sep-13 3:28am    
SelectedIndex will be -1 when there is NO SELECTION. So if you have current selected value e.g. India and you run the above code,that is index has changed.
[no name] 26-Sep-13 3:30am    
Then what is best to clear a combo box.
i tried giving ComboBox1.text="" but same problem.
Thanks7872 26-Sep-13 3:35am    
You can also use simply string.empty,but you have to handle it in selection changed event accordingly regardless of how you clear the value.

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