Connecting Tech Pros Worldwide Forums | Help | Site Map

Combo Box interaction

Newbie
 
Join Date: Mar 2009
Posts: 16
#1: May 28 '09
I have a combo box that I've hard coded Yes No into the 'Items...(Collection)' area. However, users are able to input anything into the combo box and my code breaks when saving. Is there a property that I can set that will allow users to choose Yes or No, but not allow them to enter anything?

Thanks
Mike

PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 702
#2: May 28 '09

re: Combo Box interaction


Could you post some sample code? You could have default selection...
Expand|Select|Wrap|Line Numbers
  1.  comboBox1.SelectedIndex = 0;
  2.  
Are you adding items to the combo box?
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,777
#3: May 28 '09

re: Combo Box interaction


Go to the properties of the combobox.
Change the "DropDownStyle" from "DropDown" to "DropDownList".
This style does not allow user input.

TIP: Get used to the idea that if a user can find a way to break your code THEY WILL. Put in more error correction for just about everything.

Instead of
Expand|Select|Wrap|Line Numbers
  1. if (Answer == "Yes") DoMethodA();
  2. else DoMethodB();
  3.  
Maybe something a little more robust
Expand|Select|Wrap|Line Numbers
  1. switch (Answer.ToLower())
  2. {
  3. case "yes"
  4. DoMethodA();
  5. break;
  6.  
  7. case "no"
  8. DoMethodB();
  9. break;
  10.  
  11. default
  12. DoErrorMessage();
  13. break;
  14. }
  15.  
Reply

Tags
combo, combo boxes, comboboxes