Combo Box interaction

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mwcapps
    New Member
    • Mar 2009
    • 16

    Combo Box interaction

    I have a combo box that I've hard coded Yes No into the 'Items...(Colle ction)' 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
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Could you post some sample code? You could have default selection...
    Code:
     comboBox1.SelectedIndex = 0;
    Are you adding items to the combo box?

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Go to the properties of the combobox.
      Change the "DropDownSt yle" from "DropDown" to "DropDownLi st".
      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
      Code:
      if (Answer == "Yes") DoMethodA();
      else DoMethodB();
      Maybe something a little more robust
      Code:
      switch (Answer.ToLower())
      {
      case "yes"
      DoMethodA();
      break;
      
      case "no"
      DoMethodB();
      break;
      
      default
      DoErrorMessage();
      break;
      }

      Comment

      Working...